HaxeFoundation / HaxeFoundation/haxe

Error when using `continue` in else statement inside map comprehension syntax

Open
#6,620 1 comment 0 reactions 0 assignees View on GitHub
type-system
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

This is normal array comprehension, which allows to use a `continue ` in else-statement:

```haxe
function doSomething(i:Int) trace("special" + i);
trace([for(i in 0...10) if (i != 5) 'number $i' else { doSomething(i); continue; }]);
```
I want to be able to construct a Map and add a similar else-statement.
I now get a slightly confusing error `Unexpected =>` and `Dynamic should be Void`.
```haxe
function doSomething(i:Int) trace("special" + i);
trace([for (i in 0...10) if (i != 5) i => 'number $i' else { doSomething(i); continue; }]);
```
Seen on Haxe 3.4.2:
Seen on Haxe 4.0.0 preview 1:
(both JS targets)

Contributor guide

Open the contributing guide

Research direction

Reproduce the examples from the linked try.haxe.org and try-haxe.mrcdk.com snippets with Haxe 3.4.2 and Haxe 4.0.0 preview 1 on the JavaScript target. Start by tracing compiler handling for map-comprehension syntax with an else branch and continue. Done means the Map comprehension accepts this form, preserves the continue behavior, and no longer reports the shown errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.