Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-15111] “Type of expression is ambiguous” error when initializing a class #57437

swift-ci opened this issue Aug 25, 2021 · 4 comments


Copy link

@swift-ci swift-ci commented Aug 25, 2021

Previous ID SR-15111
Radar rdar://problem/82407752
Original Reporter elidy (JIRA User)
Type Bug

Xcode Version 13.0 beta 4 (13A5201i)

Additional Detail from JIRA
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?) { = 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?'
Copy link

@typesanitizer typesanitizer commented Aug 26, 2021

@swift-ci create

Copy link

@xedin xedin commented Aug 30, 2021

elidy (JIRA User) I see that you are assigned for this one, here is a hint - in `repairFailures` for `GenericArgument` we could check whether previous element is an `ApplyArgToParam` and if so record a `AllowArgumentMismatch` fix.

Copy link

@LucianoPAlmeida LucianoPAlmeida commented Sep 1, 2021

@xedin Just an addition, this should be also the case for contextual type as well, for example `let _: Int? = stringClass?.string`

Copy link

@xedin xedin commented Sep 1, 2021

Sure, if `ApplyArgToParam` -> `AllowArgumentMismatch` fix, if `ContextualType` -> `IgnoreContextualMismatch` fix.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants