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

Produce more helpful output when module output is overwritten #716

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HT154
Copy link
Contributor

@HT154 HT154 commented Oct 20, 2024

Evaluating this module:

output: String = "abc"

Now produces

–– Pkl Error ––
Expected `output` of module `file:///$snippetsDir/input/modules/invalidOutput1.pkl` to be of type `ModuleOutput`, but got type `String`.

x | output: String = "abc"
                     ^^^^^
at output (file:///$snippetsDir/input/modules/invalidOutput1.pkl)

Resolves #709

@HT154 HT154 force-pushed the handle-overridden-module-output branch from 807587a to c030424 Compare October 20, 2024 21:50
@HT154 HT154 force-pushed the handle-overridden-module-output branch from c030424 to e756a15 Compare October 20, 2024 21:50
@@ -0,0 +1 @@
output: String = "abc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally this problem would be caught right here (override with different type), but I guess that's impossible for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd like to make Pkl stricter here and enforce that subclasses are also subtypes. Maybe something to do before we cut a 1.0 release.

Co-authored-by: translatenix <[email protected]>
@HT154 HT154 force-pushed the handle-overridden-module-output branch from cb37adb to 9d40f6d Compare October 21, 2024 01:47
Copy link
Contributor

@bioball bioball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Generally, this is the right approach. See comments for some minor issues here.

@@ -0,0 +1,3 @@
class Test {}

output: Test = new {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this and invliadOutput1 to input/errors.

I know we have some other error tests in input/modules, but those should probably be moved too. The intention is to put all testing around error messages in the errors/ dir.

@@ -0,0 +1 @@
output: String = "abc"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd like to make Pkl stricter here and enforce that subclasses are also subtypes. Maybe something to do before we cut a 1.0 release.

Object value,
VmTyped container,
Identifier propertyIdentifier,
String propertyName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a fair bit of logic here that's bespoke to reading output.value, so it's not too appropriate to be re-purposed. For example, it show different error messages based on whether output.value was explicitly assigned or not.

I think we should just copy some of the logic here that's useful, and inline that into readModuleOutput.

@translatenix
Copy link
Contributor

translatenix commented Oct 22, 2024

We'd like to make Pkl stricter here and enforce that subclasses are also subtypes.

Just a note that covariant property types aren't sound:

open class Foo { name: Any }
class Bar extends Foo { name: String } // covariant property type

bar: Bar = new { name = "bar" }
foo: Foo = bar
foo2: Foo = (foo) {
  name = 123 // static type checker is happy
}
name = foo2.name // boom

@bioball
Copy link
Contributor

bioball commented Oct 22, 2024

Yeah; unless they are marked either fixed or const (property becomes only an output and not an input)

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

Successfully merging this pull request may close these issues.

Fatal error on mistyping output
3 participants