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
pkillian opened this issue
Apr 19, 2024
· 0 comments
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.genericsFeature: generic declarations and typestypealiasFeature → type declarations: `typealias` declarations
When declaring a type-constrained typealias and implementing a struct that conforms to generic protocols, compilation can fail with an "invalid type alias" error if the typealias's declaration precedes the struct's implementation in the source file.
Reproduction
This example DOES NOT compile:
// Define two protocols; the second has an associated type constrained to the firstprotocolGenericable{}protocolExampleable<Generic>where Generic:Genericable{associatedtypeGeneric// Define a typealias that requires a generic type, using the associatedtype abovetypealiasGenericArray=Array<Generic>// Define a function that uses the above typealias to define a generic parameterfunc start(generics:GenericArray)}// Implement some structs and classes using the above protocolsstructImplementedGeneric:Genericable{}classImplementedClass<Generic:Genericable,Example:Exampleable>where Example.Generic ==Generic{}// NOTE: MOVE THIS TYPEALIAS TO END OF FILE TO BUILD SUCCESSFULLYtypealiasImplementedClassType=ImplementedClass<ImplementedGeneric,ImplementedExample<ImplementedGeneric>>structImplementedExample<Generic:Genericable>:Exampleable{// NOTE: Build failure here whenever the typealias of "ImplementedClassType"// precedes "ImplementedExample"'s declaration in the source filefunc start(generics:GenericArray){// do stuff}}
The following compilation error is encountered:
Reference to invalid type alias 'GenericArray' of type 'ImplementedExample'
This example DOES compile, with no errors:
// Define two protocols; the second has an associated type constrained to the first// Define two protocols; the second has an associated type constrained to the firstprotocolGenericable{}protocolExampleable<Generic>where Generic:Genericable{associatedtypeGeneric// Define a typealias that requires a generic type, using the associatedtype abovetypealiasGenericArray=Array<Generic>// Define a function that uses the above typealias to define a generic parameterfunc start(generics:GenericArray)}// Implement some structs and classes using the above protocolsstructImplementedGeneric:Genericable{}classImplementedClass<Generic:Genericable,Example:Exampleable>where Example.Generic ==Generic{}structImplementedExample<Generic:Genericable>:Exampleable{// NOTE: Build failure here whenever the typealias of "ImplementedClassType"// precedes "ImplementedExample"'s declaration in the source filefunc start(generics:GenericArray){// do stuff}}// NOTE: MOVE THIS TYPEALIAS ABOVE ``ImplementedExample`` TO REPRODUCE BUGtypealiasImplementedClassType=ImplementedClass<ImplementedGeneric,ImplementedExample<ImplementedGeneric>>
Expected behavior
Compilation is expected to succeed regardless of which order the typealias is defined and the struct is implemented. This prevents compilation from succeeding if the typealias is declared in a separate Swift file from the struct's implementation.
Environment
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
Additional information
I did my best to reduce the repro case down to the fewest lines of code and types, but doing any of the following fails to reproduce the issue:
Removing func start(...) from the protocol's definition
Removing ImplementedClass's first generic type Generic: Genericable
The text was updated successfully, but these errors were encountered:
pkillian
added
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
labels
Apr 19, 2024
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.genericsFeature: generic declarations and typestypealiasFeature → type declarations: `typealias` declarations
Description
When declaring a type-constrained typealias and implementing a struct that conforms to generic protocols, compilation can fail with an "invalid type alias" error if the typealias's declaration precedes the struct's implementation in the source file.
Reproduction
This example DOES NOT compile:
The following compilation error is encountered:
This example DOES compile, with no errors:
Expected behavior
Compilation is expected to succeed regardless of which order the typealias is defined and the struct is implemented. This prevents compilation from succeeding if the typealias is declared in a separate Swift file from the struct's implementation.
Environment
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
Additional information
I did my best to reduce the repro case down to the fewest lines of code and types, but doing any of the following fails to reproduce the issue:
func start(...)
from the protocol's definitionImplementedClass
's first generic typeGeneric: Genericable
The text was updated successfully, but these errors were encountered: