Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js][es6] Unexpected "Must call super() constructor before accessing this" #7869

Closed
haxiomic opened this issue Feb 25, 2019 · 6 comments
Closed
Assignees
Labels
bug platform-javascript Everything related to JS / JavaScript
Milestone

Comments

@haxiomic
Copy link
Member

haxiomic commented Feb 25, 2019

Hey @nadako, just want to say absolutely loving the new es6 class output! It's been working well for me so far but I've run into an issue with a class like this:

class Subclass extends js.html.Uint8Array {

	var member: Float;

	function new() {
		super(1);

		js.Browser.window.addEventListener('mousemove', () -> {
			member = 5;
		});
	}

}

The error is

src/Main.hx:13: lines 13-19 : Must call `super()` constructor before accessing `this` in classes derived from an extern class with constructor

It seems to happen when a member is accessed within a closure

For example, it also happens with

	var member: Float;
	function new() {
		super(1);

		function x() {
			member = 2;
		}
         }

(Haxe build 4eefb97)

@haxiomic haxiomic added platform-javascript Everything related to JS / JavaScript bug labels Feb 25, 2019
@haxiomic haxiomic changed the title [js-es=6] Unexpected "Must call super() constructor before accessing this" [js][es6] Unexpected "Must call super() constructor before accessing this" Feb 25, 2019
@nadako
Copy link
Member

nadako commented Feb 26, 2019

Err, var _gthis = this gets in the way here. @Simn why is that generated at the very top of the function instead of before the first place where it's needed?

@Simn Simn self-assigned this Feb 26, 2019
@Simn Simn added this to the Release 4.0 milestone Feb 26, 2019
@Simn
Copy link
Member

Simn commented Feb 26, 2019

Because that's how it's implemented at the moment.

@Simn
Copy link
Member

Simn commented Feb 26, 2019

I'm a bit nervous about changing this in the typer. While we can easily detect the place where it's needed at the time of typing, I'm not sure if there could be transformations which require a this variable earlier. It then makes sense to handle this during post-processing, at a point where we can be sure that nothing inserts itself before our this variable.

We might even want to handle this in the generator itself to avoid an extra filter.

@Simn
Copy link
Member

Simn commented Feb 26, 2019

Then again, given that this is a normal variable, I don't think anything could be inserted there anyway.

Simn added a commit that referenced this issue Feb 26, 2019
@Simn
Copy link
Member

Simn commented Feb 26, 2019

That should do it. Assigning to nadako to clean up after me and add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform-javascript Everything related to JS / JavaScript
Projects
None yet
Development

No branches or pull requests

4 participants