Skip to content

[SR-6062] Compiler crash when accessing Dictionary.subscript(_:default:) via key-path expression #48619

@natecook1000

Description

@natecook1000
Previous ID SR-6062
Radar rdar://problem/34835322
Original Reporter @natecook1000
Type Bug
Environment

swift/master @ aed8c33

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 21a6322780a9e431f9d545abfc86f173

Issue Description:

The following code tries to use a key-path expressions to access the key/default subscript on a dictionary, but results in a compiler crash:

var d = [1: 1, 2: 2]
print(d[keyPath: \[Int: Int].[1, default: 0]])
----
TYPE MISMATCH IN ARGUMENT 1 OF APPLY AT expression at [/Users/nate/Desktop/kp1.swift:2:18 - line:2:44] RangeText="\[Int: Int].[1, default: 0]"   argument value:   %8 = load [trivial] %7 : $*Int   parameter type: $@callee_owned () -> @out Int

I'm not sure if that's the right syntax—omitting the default: label results in an an "expression is ambiguous" error:

var d = [1: 1, 2: 2]
print(d[keyPath: \[Int: Int].[1, 0]])
----
/Users/nate/Desktop/kp1.swift:2:18: error: type of expression is ambiguous without more context
print(d[keyPath: \[Int: Int].[1, 0]])
                 ^~~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of software

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions