Skip to content

Missing diagnostic error when amending non-Object types #116

Open

Description

@9sb8ctgmws-design

Summary

When assigning a value of the wrong type to a String-typed property, the Pkl VS Code extension correctly flags a type mismatch only for primitive non‑string values (e.g., booleans), but fails to flag the error when the incorrect value is an object literal.

Example

Given a field:

my_property: String

This invalid assignment is correctly flagged:

my_property = true    // type mismatch is highlighted

But this invalid assignment is NOT flagged:

my_property {
  value = true
}

The second form assigns an object, which should not be allowed for a String-typed property, but the VS Code extension does not report any error.

Expected Behavior

The language server should report a type mismatch when a String-typed property is assigned an object literal.

Actual Behavior

No diagnostic is shown when assigning an object literal.

Environment

Extension version: 0.21.0
Pkl version: 0.30.0
VS Code: latest stable

Steps to Reproduce

  1. Create a .pkl file with a String property.
  2. Assign an object literal to it.
  3. Observe that no type-checking error is shown.

Additional Notes

This looks like a missing diagnostic case in the language server’s type checker.

Activity

  1. transferred this issue fromapple/pkl-vscodeon Nov 17, 2025
  2. HT154 commented on Nov 17, 2025

    @HT154
    Contributor

    Thanks for the report! I was able to reproduce this:

    class A {
      foo: String
    }
    
    a: A = new A {}
    
    b = (a) {
      foo {
        "oops"
      }
    }
    
    c = (a) {
      foo = true
    //      ^^^^
    //      Type mismatch.
    //      Required: String
    //      Actual: Boolean
    }

    With pkl-intellij, the same file produces both expected diagnostics:

    class A {
      foo: String
    }
    
    a: A = new A {}
    
    b = (a) {
      foo {
    //    ^
    //    Cannot amend value of type String
        "oops"
      }
    }
    
    c = (a) {
      foo = true
    //      ^^^^
    //      Type mismatch.
    //      Required: String
    //      Found: Boolean
    }
    

    This appears to affect any type that isn't an Object including primitive and collection types.

  3. changed the title [-]Type mismatch not reported when assigning object literal to primitive-typed property[/-] [+]Missing diagnostic error when amending non-`Object` types[/+] on Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions