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

parser: Enable late typing of composite literals #174

Closed
wants to merge 1 commit into from

Conversation

juliaogris
Copy link
Member

@juliaogris juliaogris commented Jul 22, 2023

Enable late typing of composite literals, such that [1] can be []num or an []any depending on what is required by the assigned
variable, parameter or return type.

This finally allows for an evy implementation of a function like font
which accepts and {}any to call as: font {size: 4}.

@github-actions
Copy link

github-actions bot commented Jul 24, 2023

firebase-deployment: https://evy-lang--174-goi2atcg.web.app (e603b1d)

@juliaogris juliaogris changed the title wip parser: Enable late typing of composite literals Jul 28, 2023
@juliaogris juliaogris requested a review from camh- July 28, 2023 13:10
Copy link
Member

@camh- camh- left a comment

Choose a reason for hiding this comment

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

🥦 This is ok for now, but for me the code in type.go with Accept, Matches, acceptLiteral and acceptStrict has gotten to the point where I can't make a lot of sense of it any more. I think it all needs some thought about unifying parts of it where possible. It logically seems sensible that Accept() would be at least partially implemented by calling Matches() and there perhaps should be just a few additional cases to deal with literal conversion and generic collections.

But I don't have the mental bandwidth this Saturday morning to figure this out. If you don't get around to merging this right away I might give some thought to that unification.

pkg/parser/ast.go Outdated Show resolved Hide resolved
Enable late typing of composite literals, such that [1] can be `
[]num` or an `[]any` depending on what is required by the assigned
variable, parameter or return type.

This finally allows for an evy implementation of a function like `font`
which accepts and `{}any` to call as: `font {size: 4}`.
@juliaogris
Copy link
Member Author

🥦 This is ok for now, but for me the code in type.go with Accept, Matches, acceptLiteral and acceptStrict has gotten to the point where I can't make a lot of sense of it any more. I think it all needs some thought about unifying parts of it where possible. It logically seems sensible that Accept() would be at least partially implemented by calling Matches() and there perhaps should be just a few additional cases to deal with literal conversion and generic collections.

Yeah, I sadly have to totally agree. Barnacles.

I leave the PR open for now.

@camh-
Copy link
Member

camh- commented Jul 30, 2023

Thinking about this in the context of the panic of assigning a different type to an element of an any collection, I think this PR might be incomplete in that it checks that a []num literal can be used when an []any is wanted, but it does not change the type of the literal to []any. I think if it did this, then the fixup for the assignment issue might get solved automatically.

@juliaogris
Copy link
Member Author

Thinking about this in the context of the panic of assigning a different type to an element of an any collection, I think this PR might be incomplete in that it checks that a []num literal can be used when an []any is wanted, but it does not change the type of the literal to []any. I think if it did this, then the fixup for the assignment issue might get solved automatically.

Well, something's broken, I'd agree there. FWIW

a:any
a = ["a" true]
a[1] = 1
print a

also panics, even though it gets assigned an []any array - something more fundamentally is broken here. I will wait for the other fix before merging this maybe.

@juliaogris juliaogris marked this pull request as draft August 9, 2023 02:39
@juliaogris
Copy link
Member Author

This is also broken:

a:[]any
a = [1]

@juliaogris
Copy link
Member Author

This comment should be addressed here I think:

#179 (comment)

@juliaogris
Copy link
Member Author

#206 is covering this now.

@juliaogris juliaogris closed this Sep 7, 2023
@juliaogris juliaogris deleted the late-lit-types branch December 17, 2023 07:48
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.

2 participants