Files
swift-mirror/test/ASTGen/diagnostics.swift
Aviva Ruben 019ddea691 Implement file-level isolation default
Leans on the previous refactor to apply file-level default isolation
via isolation inference. Follows the 'final' version of 478, so top
level globals are included in file-level default isolation. Adds
`effectivelyExplicit` method, to be used instead of checking for the
Explicit enum value directly, since a file-level default isolation
should be treated as effectively default for free un/adopt (the
non-explicit form would be unintuitive to express without the module
feature flag). This commit will diagnose @available or @diagnose until
the next commit...

Note that computeActorIsolation needs to be updated to accept isolation
on file-scope global stored properties, the old check was too broad,
and in (i think?) trying to reject isolation on computed properties of
types, also rejected it on top-level code.
2026-06-22 13:31:20 -07:00

93 lines
3.6 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-typecheck-verify-swift \
// RUN: -target %target-swift-5.9-abi-triple \
// RUN: -enable-bare-slash-regex \
// RUN: -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature DefaultIsolationPerFile
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_DefaultIsolationPerFile
// rdar://116686158
// UNSUPPORTED: asan
// expected-note@+1 3 {{first non-import declaration here}}
func testRegexLiteral() {
_ = (#/[*/#, #/+]/#, #/.]/#)
// expected-error@-1:18 {{cannot parse regular expression: quantifier '+' must appear after expression}}
// expected-error@-2:12 {{cannot parse regular expression: expected ']'}}
}
func testEditorPlaceholder() -> Int {
func foo(_ x: String) {}
foo(<#T##x: String##String#>) // expected-error {{editor placeholder in source file}})
// Make sure we don't try to parse this as an editor placeholder.
_ = `<#foo#>` // expected-error {{cannot find '<#foo#>' in scope}}
return <#T##Int#> // expected-error {{editor placeholder in source file}}
}
_ = [(Int) -> async throws Int]()
// expected-error@-1{{'async throws' must precede '->'}}
// expected-note@-2{{move 'async throws' in front of '->'}}{{15-21=}} {{21-28=}} {{12-12=async }} {{12-12=throws }}
@freestanding // expected-error {{expected arguments for 'freestanding' attribute}}
func dummy() {}
@_silgen_name("whatever", extra) // expected-error@:27 {{unexpected arguments in '_silgen_name' attribute}}
func _whatever()
struct S {
subscript(x: Int) { _ = 1 } // expected-error@:23 {{expected '->' and return type in subscript}}
// expected-note@-1:23 {{insert '->' and return type}}
}
struct ExpansionRequirementTest<each T> {}
extension ExpansionRequirementTest where repeat each T == Int {} // expected-error {{same-type requirements between packs and concrete types are not yet supported}}
#warning("this is a warning") // expected-warning {{this is a warning}}
func testDiagnosticInFunc() {
#error("this is an error") // expected-error {{this is an error}}
}
class TestDiagnosticInNominalTy {
#error("this is an error member") // expected-error {{this is an error member}}
}
#if FLAG_NOT_ENABLED
#error("error in inactive") // no diagnostis
#endif
func misisngExprTest() {
func fn(x: Int, y: Int) {}
fn(x: 1, y:) // expected-error {{expected value in function call}}
// expected-note@-1 {{insert value}} {{14-14= <#expression#>}}
}
func misisngTypeTest() {
func fn() -> {} // expected-error {{expected return type in function signature}}
// expected-note@-1 {{insert return type}} {{16-16=<#type#> }}
}
func misisngPatternTest(arr: [Int]) {
for {} // expected-error {{expected pattern, 'in', and expression in 'for' statement}}
// expected-note@-1 {{insert pattern, 'in', and expression}} {{7-7=<#pattern#> }} {{7-7=in }} {{7-7=<#expression#> }}
}
// expected-error@+1 {{'using' must appear before any non-import declaration}}
using @MainActor // expected-note {{file-level default isolation previously declared here}}
// expected-error@+1 {{'using' must appear before any non-import declaration}}
using nonisolated // expected-error {{invalid redeclaration of file-level default isolation}}
// expected-error@+1 {{'using' must appear before any non-import declaration}}
using @Test
// expected-error@-1 {{cannot find type 'Test' in scope}}
// expected-note@-2 {{'using' supports '@MainActor', 'nonisolated', '@available', and '@diagnose'}}
using test
// expected-error@-1 {{expected '@MainActor', 'nonisolated', '@available', or '@diagnose' after 'using'}}