Function body of extern class being completed ignored #5898

Open
kevinresol opened this Issue Dec 21, 2016 · 11 comments

Projects

None yet

5 participants

@kevinresol
Contributor
kevinresol commented Dec 21, 2016 edited

The following code parses but should not.
Same behaviour in 3.2, 3.3 and 3.4

class Main {
	static function main() {
		$type(Extern.foo()); // Float
	}
}

extern class Extern {
	static function foo():Float-Float; // note the typo, should be Float->Float
}
@back2dos
Member

The code should parse, because essentially it is this:

extern class Extern {
	static function foo():Float
           -Float;
}

However it should not pass the typer. Apparently function bodies in extern classes get completely ignored unless the function is inline: http://try.haxe.org/#B09A9

@kevinresol
Contributor

Oh, yes it is. Well, what if the compiler throws something like "extern function should not have a body"?

@back2dos
Member

IIRC in the good old days we had that error message ;)

@nadako
Member
nadako commented Dec 21, 2016

I find parsing function f():Float-Float as function f():Float -Float wrong...

@back2dos
Member

I don't see as what else it should be parsed. Ordinarily, it's not a problem, because - is not valid on any type. But of course if for some reason it never goes through the typer, the result is indeed surprising.

@Simn
Member
Simn commented Dec 22, 2016

I agree this should parse, but not type. Not really sure why extern non-inline expressions are allowed at the moment. Could somebody check that with 3.2 or something?

@nadako
Member
nadako commented Dec 22, 2016

I remember asking about that and the answer was something regarding easily making non-extern classes extern for modular haxe applications or something like that.

@Simn
Member
Simn commented Dec 22, 2016

@ncannasse: Any opinions?

@back2dos
Member

I remember asking about that and the answer was something regarding easily making non-extern classes extern for modular haxe applications or something like that.

If that is the reason, then I think it makes little sense. One can always just register a build macro per --macro addGlobalMetaData to accomplish exactly that behavior in any specified scope (including the global one). But code just being ignored is not exactly what one would expect.

@kevinresol
Contributor
kevinresol commented Dec 22, 2016 edited

Another side-effect is that macro function inside extern class has to be marked as inlined in order for it to work: https://github.com/haxe-react/hxjs-redux/blob/4236aa4/src/redux/Redux.hx#L13

which is not so intuitive. Because I think that macro functions are "inlined" by its nature.

@kevinresol kevinresol changed the title from Incorrect parsing to Function body of extern class being completed ignored Dec 22, 2016
@ncannasse
Member

We could forbid functions body in extern classes, unless it is inline. If it's a problem we could still ignore empty block for the sake of backward compatibility.

@Simn Simn modified the milestone: 4.0 Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment