Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot flow-type through qualified access #21

Open
bvalyou opened this issue Apr 5, 2024 · 2 comments
Open

Cannot flow-type through qualified access #21

bvalyou opened this issue Apr 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@bvalyou
Copy link

bvalyou commented Apr 5, 2024

Relates to apple/pkl#402

Summary

Subtype checks do not register within a compound conditional if the object being type checked is dereferenced from another variable.

How to reproduce

It's actually pretty interesting - I've spent the last 20 minutes trying to find a minimal reproducible example and after talking through it for a few minutes, I found it.

This does not reproduce it:

import "@k8s/K8sResource.pkl"
import "@k8s/api/core/v1/ConfigMap.pkl"

function testCompoundCondition(resource: K8sResource) = resource is ConfigMap
  && resource.metadata.name == "foo" // metadata autocompletes

This does:

import "@k8s/K8sResource.pkl"
import "@k8s/api/core/v1/ConfigMap.pkl"

class ThingWithK8sResource {
  resource: K8sResource
}

function testCompoundCondition(thing: ThingWithK8sResource) = thing.resource is ConfigMap
  && thing.resource.metadata.name == "foo" // Unresolved reference: metadata

More details

When amending a Listing<K8sResource> to update a named ConfigMap, this member predicate line is not recognizing that we already know the K8sResource is of subtype ConfigMap, which has a metadata attribute:

[[this is ConfigMap && metadata.name == environment.resourceName("app-env")]] {
image

On the subsequent line the amend body properly identifies the data attribute as belonging to the ConfigMap, but it's not resolved within the predicate itself.

Versions

Pkl 0.25.2
Pkl IntelliJ 0.26.0

@bioball bioball changed the title Compound conditionals sometimes don't register prior type checks Cannot flow-type through qualified access Apr 9, 2024
@bioball bioball added the enhancement New feature or request label Apr 9, 2024
@bioball
Copy link
Contributor

bioball commented Apr 9, 2024

Thanks for the report. This is a hard problem; most other language plugins can't do this either. The only one I'm aware of that can do this is Kotlin.

@holzensp
Copy link
Contributor

holzensp commented Apr 10, 2024

I know that Hack struggled with this too, at least, after any method was called on the outer object. In their case, it's duet mutability. Since Pkl is immutable, this should (famous last words) be generally decidable.

Thanks for a great minimal repro, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants