swiftlang/swift
Vedi su GitHub[SR-15111] “Type of expression is ambiguous” error when initializing a class
Open
#57.437 aperta il 25 ago 2021
bugcompilerdiagnostics qualityexpressionsgood first issueoptional chainingswift 5.9type checkertype inference
Metriche repository
- Star
- (69.989 star)
- Metriche merge PR
- (Merge medio 8g 17h) (510 PR mergiate in 30 g)
Descrizione
| Previous ID | SR-15111 |
| Radar | rdar://problem/82407752 |
| Original Reporter | elidy (JIRA User) |
| Type | Bug |
Xcode Version 13.0 beta 4 (13A5201i)
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug, DiagnosticsQoI, StarterBug, TypeChecker |
| Assignee | elidy (JIRA) |
| Priority | Medium |
md5: 37c1160eb7b2424ea42b3ec849906fef
Issue Description:
When a class is initialized, passing an argument as a property of an optional class instance of incorrect type results in “Type of expression is ambiguous” error.
class IntClass {
var int: Int?
init(int: Int?) {
self.int = int
}
}
class StringClass {
var string: String? = "hello"
}
var stringClass: StringClass? = StringClass()
IntClass(int: stringClass?.string)
//Type of expression is ambiguous without more context
//Expected error: Cannot convert value of type 'String?' to expected argument type 'Int?'
var stringValue = stringClass?.string
IntClass(int: stringValue)
//Cannot convert value of type 'String?' to expected argument type 'Int?'