Why Does The Enum-Constructor-Switch Constellation Does Not Work Anymore?

78 views
Skip to first unread message

Arnim Schachtschabel

unread,
Aug 31, 2017, 12:49:54 PM8/31/17
to Haxe
Hello Community,

in previous versions (evidently up to haxe 3-3-0 RC) it was possible to get
the value nested inside an enum constructor with a switch.

It then looked like this:


var uniqueName : String = "";
>
> switch( transFishBowlContainer )
> {
> case TransFishBowlContainer.fishBowl( fishBowl ) :
> uniqueName = fishBowl.uniqueName;
>
> case TransFishBowlContainer.transFishBowlCypher( transFishBowlCypher ) :
> uniqueName = transFishBowlCypher.fishBowlUniqueName;
>
> } // switch( transFishBowlContainer )
>
>
But this does not work in Haxe 3-4-2 anymore.

An error is thrown. Apparently the compiler resolves the enum constructor
as a function.

Also see here:
https://try.haxe.org/#82A7F

*Why is that?* This keeps me from updating at the moment. The change of
code even with simple workarounds would bust my timeline as I have used
this enum-constructor-switch constellation quite often.

Is it intended to be that way? Or is it a bug?
If it is intended, what is the reason for that?

Kind regards
Arnim


Dan Korostelev

unread,
Aug 31, 2017, 1:27:47 PM8/31/17
to Haxe
Looks like there's a problem when the capture var name is the same as the constructor name. It should be fixable, I think, because the expected type is known, so it can figure out that this is a capture var.

enum E {
a(v:Int);
}

class Main {
static function main() {
switch (a(1)) {
case a(a):
}
}
}

четверг, 31 августа 2017 г., 19:49:54 UTC+3 пользователь Arnim Schachtschabel написал:

Arnim Schachtschabel

unread,
Sep 1, 2017, 4:21:58 AM9/1/17
to Haxe
Hello Dan,

thank you for your reply. You are absolutely right.

So the effort of the fixing within my code will be more or less acceptable.

But I will write an issue report anyway. I think this should also be fixed within HAXE itself.

Kind regareds
Arnim

Arnim Schachtschabel

unread,
Sep 1, 2017, 4:33:03 AM9/1/17
to Haxe
Anyhow the google group forum seems to be a little bit buggy at the moment.

Yesterday I experienced trouble when I wanted to publish a post. It was reported to be published at 05:00 AM (about 8 hours later), I did not find it in the list of new posts anyway.

Also when I write an answer to a reply of someone, the textfield shrinks continuously, so I can't read, what I have written anymore.

Maybe this is the reason, why I could not read the post of Simon Krajewski.

Thank you, Simon, for your reply anyway. I have read it in the e-mail, the forum sent to me.

Simon Krajewski

unread,
Sep 1, 2017, 4:34:50 AM9/1/17
to haxe...@googlegroups.com
I accidentally sent it to you instead of the list. There are different reply buttons in thunderbird now...

Simon
Reply all
Reply to author
Forward
0 new messages