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

Incorrect prototype handling #207

Open
SeeSpring opened this issue Sep 10, 2024 · 2 comments
Open

Incorrect prototype handling #207

SeeSpring opened this issue Sep 10, 2024 · 2 comments
Assignees
Labels
bug Something isn't working checking Issues around checking

Comments

@SeeSpring
Copy link

let a = {a:0}
let b = {get a(){return 0}}
let c = Math.random() ? a : b
let d = {}
Object.setPrototypeOf(d, c)
let e = ''
if ('a' in d) {
  e = 0
}
e.toUpperCase()

Throws Uncaught TypeError: e.toUpperCase is not a function at runtime

@kaleidawave
Copy link
Owner

Yes there seems to be some issues with https://kaleidawave.github.io/ezno/playground/?id=klnuy

  1. has_property could do better on unions or condition results (in the case of the value assigned to c). The currently do not look at both sides and figure a result. (the first print_type("a" in c); should be true)
  2. It seems that the setPrototypeOf does not register the prototype when the prototype is a conditional type. It works for setPrototypeOf(d, a) and setPrototypeOf(d, b) but not with c. Once the property access works and returns a result, then "a" in d should return true (rather than false and the example above should work 🤞)

@kaleidawave kaleidawave added bug Something isn't working checking Issues around checking labels Sep 14, 2024
@kaleidawave kaleidawave self-assigned this Nov 12, 2024
@kaleidawave
Copy link
Owner

Have investigated this just now and I think I have found two problems

  1. setPrototypeOf is an internal function. Most internal functions shouldn't run if there argument are not constants although some should. Have added it to the list that run if argument is generic (like conditional types are)
  2. The access on the prototype looks up "simple object properties", rather than running the general try get property on type. Should change which function is called.

Should have a fix in #209 for it later (should do in separate commit)

kaleidawave added a commit that referenced this issue Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working checking Issues around checking
Projects
None yet
Development

No branches or pull requests

2 participants