mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Re-implement operator and precedencegroup decl lookup to use `namelookup::getAllImports` and existing decl shadowing logic. This allows us to find operator decls through `@_exported` imports, prefer operator decls defined in the same module over imported decls, and fixes a couple of other subtle issues. Because this new implementation is technically source breaking, as we can find multiple results where we used to only find one result, it's placed behind the new Frontend flag `-enable-new-operator-lookup` (with the aim of enabling it by default when we get a new language mode). However the new logic will always be used if the result is unambiguous. This means that e.g `@_exported` operators will be instantly available as long as there's only one candidate. If multiple candidates are found, we fall back to the old logic. Resolves SR-12132. Resolves rdar://59198796.
32 lines
1.4 KiB
Swift
32 lines
1.4 KiB
Swift
// RUN: %target-swift-frontend -typecheck -verify -primary-file %s %S/Inputs/redeclaration_other.swift -enable-new-operator-lookup
|
|
|
|
precedencegroup RedeclaredAcrossFiles {} // expected-error {{precedence group redeclared}}
|
|
|
|
precedencegroup RedeclaredSameFile {} // expected-note {{previous precedence group declaration here}}
|
|
precedencegroup RedeclaredSameFile {} // expected-error {{precedence group redeclared}}
|
|
|
|
precedencegroup RedeclaredSameFile2 { // expected-note {{previous precedence group declaration here}}
|
|
assignment: true
|
|
}
|
|
precedencegroup RedeclaredSameFile2 {} // expected-error {{precedence group redeclared}}
|
|
|
|
// These are all declared in the other file.
|
|
infix operator ^^^ // expected-error {{operator redeclared}}
|
|
prefix operator >>> // expected-error {{operator redeclared}}
|
|
postfix operator <<< // expected-error {{operator redeclared}}
|
|
infix operator ^^^^ // expected-error {{operator redeclared}}
|
|
|
|
// This is declared as an infix operator in the other file, so no problem.
|
|
prefix operator &&&
|
|
postfix operator &&&
|
|
|
|
infix operator %%% // expected-note {{previous operator declaration here}}
|
|
infix operator %%% // expected-error {{operator redeclared}}
|
|
|
|
prefix operator %%% // expected-note {{previous operator declaration here}}
|
|
prefix operator %%% // expected-error {{operator redeclared}}
|
|
|
|
precedencegroup P2 {}
|
|
infix operator *** : P2 // expected-note {{previous operator declaration here}}
|
|
infix operator *** // expected-error {{operator redeclared}}
|