mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This crash happens because shouldAddSelfFixit (a check for the expected_self_before_reference diagnotic) performs name lookup inside the parser, which causes a search for extensions, which triggers the mangler, which can get confused if we are in an unfinished declaration (a PatternBindingInitilizer in this case). A cleaner fix would be to move that logic inside Sema, but it would require much more refactoring that I don’t feel comfortable doing. Instead, this band-aid checks if the innermost type is inside a local context. If that’s the case, we can ignore the search for extensions.
56 lines
1.5 KiB
Swift
56 lines
1.5 KiB
Swift
// RUN: %target-swift-frontend -typecheck -verify %s
|
|
|
|
class A1 {
|
|
func foo1() {}
|
|
func foo2() {
|
|
var foo1 = foo1() // expected-error {{variable used within its own initial value; use 'self.' to refer to the instance method}}{{16-16=self.}}
|
|
}
|
|
}
|
|
|
|
class A2 {
|
|
var foo1 = 2
|
|
func foo2() {
|
|
// FIXME: "the var" doesn't sound right.
|
|
var foo1 = foo1 // expected-error {{variable used within its own initial value; use 'self.' to refer to the var}}{{16-16=self.}}
|
|
}
|
|
}
|
|
|
|
class A3 {
|
|
func foo2() {
|
|
// FIXME: this should also add fixit.
|
|
var foo1 = foo1() // expected-error {{variable used within its own initial value}}{{none}}
|
|
}
|
|
func foo1() {}
|
|
}
|
|
|
|
class A4 {
|
|
func foo2() {
|
|
var foo1 = foo1 // expected-error {{variable used within its own initial value}}{{none}}
|
|
}
|
|
}
|
|
|
|
func localContext() {
|
|
class A5 {
|
|
func foo1() {}
|
|
func foo2() {
|
|
var foo1 = foo1() // expected-error {{variable used within its own initial value; use 'self.' to refer to the instance method}}{{18-18=self.}}
|
|
}
|
|
|
|
class A6 {
|
|
func foo1() {}
|
|
func foo2() {
|
|
var foo1 = foo1() // expected-error {{variable used within its own initial value; use 'self.' to refer to the instance method}}{{20-20=self.}}
|
|
}
|
|
}
|
|
|
|
extension E { // expected-error {{declaration is only valid at file scope}}
|
|
class A7 {
|
|
func foo1() {}
|
|
func foo2() {
|
|
var foo1 = foo1() // expected-error {{variable used within its own initial value; use 'self.' to refer to the instance method}}{{22-22=self.}}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|