apple / pkl-intellij

JetBrains editor plugins providing Pkl language support
https://pkl-lang.org/intellij/current/index.html
Apache License 2.0
49 stars 10 forks source link

Incorrect static analysis over union-with-default `Mapping` value types #62

Open HT154 opened 3 weeks ago

HT154 commented 3 weeks ago

IntelliJ complains about code that is considered valid by pkl eval. Repro, with IntelliJ diags commented inline:

class Gizmo {
  name: String
}

x: Mapping<String, *Gizmo|Any> = new {
  ["a"] {
//      ^ Cannot amend value of type `Any`
    name = "hello"
  }
  ["c"] = new {
//        ^^^ Cannot instantiate type `Any`
    name = "goodbye"
  }
  ["c"] = 123
}

typealias GizmoAny = *Gizmo|Any

y: Mapping<String, GizmoAny> = new {
  ["a"] {
//      ^ Cannot amend value of type `GizmoAny`
    name = "hello"
  }
  ["c"] = new {
//        ^^^ Cannot instantiate type `GizmoAny`
    name = "goodbye"
  }
  ["c"] = 123
}