Crash on emitting SIL

Hi, I'm facing curious situation like below

struct A<Element> {
	var value: [Element]
}

extension A {
	var value: [Element] { return [] }
}

this code make stopped on SIL generation. I'm expect redeclaration error or multimatching parameter but why just stopped SIL generate process. this code make An internal error occured. Source editor functionality is limited. Attempting to restore... to your Xcode.

It is possible to get a clear error by specifying the generic type.

extension A where Element == Int 

it make clear redeclaration error message.
or
A protocol declaration can also cause a proper error.

protocol P {
	associatedtype Element
	var value: [Element] { get }
}
struct A<Element>: P {
	var value: [Element]
}

extension A {
	var value: [Element] { return [] }
}

it make clear multiple matching error.

What problems of first codes make SIL generate crash? I seek your advice.

Best Regards,

That is certainly a bug. Report it to Apple's Bug Reporter.

The redeclared property doesn't necessarily have to be generic to trigger the crash.

struct A<Element> {  var value: Int }

extension A { var value: Int { return 0 }}
1 Like

thank you. I have been studying AST, SIL for 3 days because of this problem, and I was able to study SIL quite a bit, but I was suffering from not knowing the cause of the problem. Thanks to that, I can bug report to Apple coolly.

You can create an issue at bugs.swift too since this is a compiler-related bug.

1 Like

I went ahead and filed a bug for this here: [SR-7249] Compiler crash for redeclaration in extension of generic type · Issue #49797 · apple/swift · GitHub, and opened a pull request to fix here: https://github.com/apple/swift/pull/15412.

1 Like

oh such nice. thanks!