HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.09k stars 646 forks source link

Issue 705 - Allow typing of EIn for Context.typeof - haxe #705

Closed issuesbot closed 11 years ago

issuesbot commented 11 years ago

[Google Issue #705 : https://code.google.com/p/haxe/issues/detail?id=705] by simon.kr...@simn.de, at 14/03/2012, 15:16:00 Could we allow EIn to be typed to the type of the iterator variable if need_val is true? This would greatly simplify some macros where it's currently quite a hassle to get the type right.

I attached a proof of concept patch that returns a typed null, which probably isn't optimal, but the best I could come up with for now.

With this, the iterator type of a for-loop like for (c in [new Complex()]) can easily be obtained through case EFor(it, expr): trace(Context.typeof(it)); // TInst(deep.math.Complex,[])

issuesbot commented 11 years ago

[comment from ncanna...@gmail.com, published at 14/03/2012, 15:50:23] That would make invalid syntax become valid such as "var x = c in []"

issuesbot commented 11 years ago

[comment from simon.kr...@simn.de, published at 14/03/2012, 16:30:52] I see, I thought need_val was directly related to the use from Context.typeof(). That's too bad because it would be really useful.

A different take: It's often necessary to have some custom var declarations in the context when using typeof. This is usually replicated by keeping an Array of var declarations around and pass it along with the expression to typeof as EVars, like tink does it: https://github.com/back2dos/tinkerbell/blob/master/src/tink/macro/tools/ExprTools.hx#L180

Could typeof be changed to accept an optional second argument that works exactly like this? Then special cases could be handled in Interp.typeof directly, e.g. a singular EIn could be typed in a temporary EFor and the iterator type would then be extracted.

issuesbot commented 11 years ago

[comment from ncanna...@gmail.com, published at 26/03/2012, 09:09:20] There's been a lengthy discussion on [haxedev], not sure what was the outcome so I'm closing this one for now.