Skip to content

[SourceKit] Suppress oslog_invalid_log_message diagnostic in live issues #38778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/SourceKit/Sema/oslog.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// REQUIRES: VENDOR=apple

// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s

// RUN: %target-build-swift -emit-module -module-name Lib -o %t -Xfrontend -experimental-allow-module-with-compiler-errors -Xfrontend -experimental-skip-all-function-bodies %t/lib.swift
// RUN: %sourcekitd-test -req=sema %t/main.swift -- %t/main.swift -I%t -sdk %sdk -Xfrontend -experimental-allow-module-with-compiler-errors | %FileCheck %s
// CHECK-NOT: oslog_invalid_log_message

// BEGIN lib.swift
import os

public struct Foo {
public let prop: String
public init() { self.prop = "boop" }
}

@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
extension OSLogInterpolation {
@_optimize(none)
@_transparent
@_semantics("oslog.requires_constant_arguments")
public mutating func appendInterpolation(_ value: @autoclosure @escaping () -> Foo) {
let v = value()
appendInterpolation(v.prop)
}
}

// BEGIN main.swift
import os
import Lib

if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
let logger = Logger()
logger.log("Log a foo: \(Foo())")
}
9 changes: 8 additions & 1 deletion tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "swift/AST/DiagnosticsClangImporter.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/AST/DiagnosticsSIL.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Demangling/ManglingUtils.h"
#include "swift/Frontend/Frontend.h"
Expand Down Expand Up @@ -83,7 +84,13 @@ void EditorDiagConsumer::handleDiagnostic(SourceManager &SM,
}

// Filter out benign diagnostics for editing.
if (Info.ID == diag::lex_editor_placeholder.ID)
// oslog_invalid_log_message is spuriously output for live issues as modules
// in the index build are built without function bodies (including inline
// functions). OSLogOptimization expects SIL for bodies and hence errors
// when there isn't any. Ignore in live issues for now and re-evaluate if
// this (not having SIL for inline functions) becomes a more widespread issue.
if (Info.ID == diag::lex_editor_placeholder.ID ||
Info.ID == diag::oslog_invalid_log_message.ID)
return;

bool IsNote = (Info.Kind == DiagnosticKind::Note);
Expand Down