Skip to content

[BUGFIX] Fix map comprehension only working with Int keys - #542

Draft
NotHyper-474 wants to merge 1 commit into
FunkinCrew:developfrom
NotHyper-474:fix/map-comp-type
Draft

NotHyper-474 wants to merge 1 commit into
FunkinCrew:developfrom
NotHyper-474:fix/map-comp-type

Conversation

@NotHyper-474

@NotHyper-474 NotHyper-474 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

The way map comprehension was recently implemented completely disregards the type the Map may have on runtime, as the way it directly calls makeMap will always cause the generated Map to be an IntMap. This is the exact reason I said a typer should be implemented first.

So, after being disgruntled at my suggestion having absolutely no consideration put into it, I decided to spend some hours fixing the jank by replacing with a different jank: a hacky fix.
Basically, we hijack the map comprehension body, manually initializing the temporary _g variable with an object that intercepts the generated set calls to populate arrays of keys and values, then finally we copy the result over to a Map with the correspondent type.

Screenshots

(Note: the __name__ is exclusive to HashLink and I used it 'cause I was lazy to type Type.getClassName(Type.getClass(...)).)
image

image

@NotHyper-474 NotHyper-474 changed the title [BUGFIX] Fix map comprehension only creating Int maps [BUGFIX] Fix map comprehension only working with Int keys Oct 7, 2026
@nykwono

nykwono commented Oct 8, 2026

Copy link
Copy Markdown

So, after being disgruntled at my suggestion having absolutely no consideration put into it, I decided to spend some hours fixing the jank by replacing with a different jank: a hacky fix.

That was lowkey my bad I apologize🥀 as when I implemented it it was working fine with me and figured it would ALWAYS return to be an IMap<Dynamic, Dynamic> at the least which I hadn't really figured to why it wouldn't with makeMap?

Though I will say I feel as if your implementation may be a bit, TOO hacky, as it's checking specifically for the expression count which we can't always make sure is 3 (EParent 😬), I feel like maybe re-implementing the comprehension that accounts more for the entries that are provided would be a better solution, no?

@NotHyper-474

Copy link
Copy Markdown
Contributor Author

I feel like maybe re-implementing the comprehension that accounts more for the entries that are provided would be a better solution, no?

Care to elaborate?

@nykwono

nykwono commented Oct 8, 2026

Copy link
Copy Markdown

I feel like maybe re-implementing the comprehension that accounts more for the entries that are provided would be a better solution, no?

Care to elaborate?

Well, since we know explicitly from the parser that we're dealing with a map/array comprehension. I feel like we could use that to easily make a new Expr enum field that defines the properties for said Map/Array comprehension. This could also help with a bit of psuedo-typing with Arrays as well if im not mistaken 🤔

@NotHyper-474

Copy link
Copy Markdown
Contributor Author

Well, since we know explicitly from the parser that we're dealing with a map/array comprehension. I feel like we could use that to easily make a new Expr enum field that defines the properties for said Map/Array comprehension. This could also help with a bit of psuedo-typing with Arrays as well if im not mistaken 🤔

So... with that the Parser would just tell to the Interpreter if the comprehension is either a Map or Array one, then it would populate it? I'm not sure I follow.

@nykwono

nykwono commented Oct 8, 2026 •

Copy link
Copy Markdown

Well, since we know explicitly from the parser that we're dealing with a map/array comprehension. I feel like we could use that to easily make a new Expr enum field that defines the properties for said Map/Array comprehension. This could also help with a bit of psuedo-typing with Arrays as well if im not mistaken 🤔

So... with that the Parser would just tell to the Interpreter if the comprehension is either a Map or Array one, then it would populate it? I'm not sure I follow.

Yes, the parser already tells you whether its a Map or Array compr thanks to the _a & _g, I feel like you could use this to your advantage to then have a new expr to then make initialize a array/map comprehension instead if that makes sense.

@NotHyper-474
NotHyper-474 marked this pull request as draft October 8, 2026 18:35
@NotHyper-474

Copy link
Copy Markdown
Contributor Author

After trying to implement it via a new AST/Expr node, I realized I'd have to somehow turn it back into the original code in the Printer because script merging would rely on it, and so I gave up 'cause that's a can of worms I'd rather not open.

So the only change I did was remove the specific block expr length check. Maybe I'm too stupid to make a proper implementation.

@NotHyper-474
NotHyper-474 marked this pull request as ready for review October 8, 2026 22:33
@NotHyper-474

Copy link
Copy Markdown
Contributor Author

...I think I have an idea, though it'll have to wait.

@NotHyper-474
NotHyper-474 marked this pull request as draft October 8, 2026 23:11
@nykwono

nykwono commented Oct 9, 2026

Copy link
Copy Markdown

...I think I have an idea, though it'll have to wait.

I think you'll cook, I trust you hard brother ❤️🙏

This branch has not been deployed

No deployments
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