You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Xcode Version 10.1 (10B61)
Apple Swift version 4.2.1
All examples run in a Swift Playground.
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: d4d208ed9f32df731ab2823a18e0708c
Issue Description:
There are several issues surrounding protocols with default implementations in extensions. The first two here are definitely bugs, the third is arguably a bug.
1. Incorrect behavior for statically defined constants
protocolA {
vara: Int { get }
}
extensionA {
vara: Int {
return1
}
}
classImplementation: A {
staticleta: Int = 2leta = Implementation.a
}
letimplementation = Implementation()
print(implementation.a)
print(implementation.aasInt)
print((implementationasA).aasInt)
Expected output: "2 2 2"
Actual output: "2 2 1".
Note: Moving the static variable declaration to another class produces the expected output. Declaring the `let a` as `let a: Int` also produces the expected output.
2. Declaring uninitialized variables not caught by the compiler:
classZ {}
protocolA {
varz: Z { get }
}
extensionA {
varz: Z {
returnImplementation().z
}
}
structImplementation: A {
letz = globalZ
}
letglobalZ = Implementation().z
Expectation: compiler error. Circular definition.
Actual error: "Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x0)."
3. Type based variable overloading
protocolA {
vara: Float { get }
}
extensionA {
vara: Float {
return1
}
}
classImplementation: A {
leta = 2
}
letimplementation = Implementation()
print(implementation.a)
print(implementation.aasFloat)
print((implementationasA).a)
Expected output: Compiler error or "2.0 2.0 2.0".
Actual output: "2 1.0 1.0"
The text was updated successfully, but these errors were encountered:
Environment
Xcode Version 10.1 (10B61)
Apple Swift version 4.2.1
All examples run in a Swift Playground.
Additional Detail from JIRA
md5: d4d208ed9f32df731ab2823a18e0708c
Issue Description:
There are several issues surrounding protocols with default implementations in extensions. The first two here are definitely bugs, the third is arguably a bug.
1. Incorrect behavior for statically defined constants
Expected output: "2 2 2"
Actual output: "2 2 1".
Note: Moving the static variable declaration to another class produces the expected output. Declaring the `let a` as `let a: Int` also produces the expected output.
2. Declaring uninitialized variables not caught by the compiler:
Expectation: compiler error. Circular definition.
Actual error: "Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x0)."
3. Type based variable overloading
Expected output: Compiler error or "2.0 2.0 2.0".
Actual output: "2 1.0 1.0"
The text was updated successfully, but these errors were encountered: