Validation for alias doesn't execute #91

Closed
opened 2025-12-30 01:20:40 +01:00 by adam · 2 comments
Owner

Originally created by @miroslav-filipovic on GitHub (Feb 28, 2024).

I tried following example using 0.25.2 and 0.26.0, but both versions passed with no error.

typealias ListingAlias = Listing<Int16>(isDistinctBy((d) -> "not unique"))

temp1 = new ListingAlias {
    1 2 3 4
}

output {
    renderer = new YamlRenderer {}
}

As far as I understand, this should fail because isDistinctBy wouldn't be unique for each element.

Using next example I managed to get error:

class ListingClass {
    inner: Listing<Int16>(isDistinctBy((d) -> "not unique"))
}

temp2 = new ListingClass {
    inner = new Listing {
        1 2 3 4
    }
}

output {
    renderer = new YamlRenderer {}
}

which gave following output

Type constraint `isDistinctBy((d) -> "not unique")` violated.

...

I think examples are very similar and both should fail, but latter adds more complexity that I'd like to avoid. Am I doing something completely wrong or this is expected? If any of those are the case, let me know and I will close the issue.

Originally created by @miroslav-filipovic on GitHub (Feb 28, 2024). I tried following example using 0.25.2 and 0.26.0, but both versions passed with no error. ``` typealias ListingAlias = Listing<Int16>(isDistinctBy((d) -> "not unique")) temp1 = new ListingAlias { 1 2 3 4 } output { renderer = new YamlRenderer {} } ``` As far as I understand, this should fail because `isDistinctBy` wouldn't be unique for each element. Using next example I managed to get error: ``` class ListingClass { inner: Listing<Int16>(isDistinctBy((d) -> "not unique")) } temp2 = new ListingClass { inner = new Listing { 1 2 3 4 } } output { renderer = new YamlRenderer {} } ``` which gave following output ``` Type constraint `isDistinctBy((d) -> "not unique")` violated. ... ``` I think examples are very similar and both should fail, but latter adds more complexity that I'd like to avoid. Am I doing something completely wrong or this is expected? If any of those are the case, let me know and I will close the issue.
adam closed this issue 2025-12-30 01:20:40 +01:00
Author
Owner

@bioball commented on GitHub (Feb 28, 2024):

Right now, Pkl doesn't execute type checks when you do new Listing<Type>, or new Mapping<Type, Type>. This is a known bug.

To get these type checks to execute, you need to assign the type to your property.

For example:

temp1: ListingAlias = new { 1; 2; 3; 4 }
@bioball commented on GitHub (Feb 28, 2024): Right now, Pkl doesn't execute type checks when you do `new Listing<Type>`, or `new Mapping<Type, Type>`. This is a known bug. To get these type checks to execute, you need to assign the type to your property. For example: ``` temp1: ListingAlias = new { 1; 2; 3; 4 } ```
Author
Owner

@miroslav-filipovic commented on GitHub (Feb 28, 2024):

Nice, thanks!

@miroslav-filipovic commented on GitHub (Feb 28, 2024): Nice, thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#91