Skip to content

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

@swift-ci

Description

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

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?) {
        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?'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsgood first issueGood for newcomersoptional chainingFeature → expressions: optional chainingswift 5.9type checkerArea → compiler: Semantic analysistype inferenceFeature: type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions