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

Stack overflow when parameter name is same as object property name #444

Open
sin-ack opened this issue Apr 22, 2024 · 2 comments
Open

Stack overflow when parameter name is same as object property name #444

sin-ack opened this issue Apr 22, 2024 · 2 comments

Comments

@sin-ack
Copy link

sin-ack commented Apr 22, 2024

The following fails:

class Point {
  x: Float
  y: Float
  z: Float
}

function Point(x: Float, y: Float, z: Float) = new Point { x = x; y = y; z = z }

foo = Point(1.0, 2.0, 3.0)
bar = foo.x

With the following error:

–– Pkl Error ––
A stack overflow occurred.

┌─ 643 repetitions of:
│ 7 | function Point(x: Float, y: Float, z: Float) = new Point { x = x; y = y; z = z }
│                                                                    ^
│ at test#Point.x (file:///.../test.pkl, line 7)
└─

10 | bar = foo.x
           ^^^^^
at test#bar (file:///.../test.pkl, line 10)

106 | text = renderer.renderDocument(value)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/3a31188/stdlib/base.pkl#L106)

The following works as expected, however:

function Point(x_: Float, y_: Float, z_: Float) = new Point { x = x_; y = y_; z = z_ }

I would expect object properties to be in a different "namespace" and such not cause a self-assignment.

@holzensp
Copy link
Contributor

You might expect that, but does that mean you'd also expect that as soon as you're inside a function, you can't reference object properties at all anymore? How would you write this?

function Uniform(x_: Float): Point = new { x = x_; y = x; z = x }

@sin-ack
Copy link
Author

sin-ack commented Apr 26, 2024

Hmm, you are right. Then the issue becomes "it should give a nice error instead of stack overflowing" :)

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

No branches or pull requests

2 participants