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

[typer] abstract constructors shouldn't be allowed to return a value #7809

Closed
Gama11 opened this issue Feb 18, 2019 · 5 comments · Fixed by #9278
Closed

[typer] abstract constructors shouldn't be allowed to return a value #7809

Gama11 opened this issue Feb 18, 2019 · 5 comments · Fixed by #9278

Comments

@Gama11
Copy link
Member

Gama11 commented Feb 18, 2019

(extracted from #7751)

This compiles, despite the :Void type hint on new:

class Main {
	public static function main() {
		new Test(0);
	}
}

abstract Test(Int) from Int {
	public function new(i:Int):Void {
		this = i;
		return i;
		// return; // Void should be Test
	}
}
@Gama11 Gama11 added the bug label Feb 18, 2019
@Simn Simn added this to the Release 4.0 milestone Feb 27, 2019
@Simn Simn self-assigned this Feb 27, 2019
@Simn Simn modified the milestones: Release 4.0, Release 4.1 Mar 18, 2019
@Simn
Copy link
Member

Simn commented Mar 18, 2019

I'm removing the 4.0 milestone from this because I don't find this clear cut. Why should class constructors be allowed to return early but abstract constructors not? I think the actual problem here is with the typing.

@Gama11
Copy link
Member Author

Gama11 commented Mar 18, 2019

I don't think anybody wanted to disallow returns, but it should probably be return;, not return value;? Quoting @ncannasse:

they should not be allowed to return any value

@Simn
Copy link
Member

Simn commented Mar 18, 2019

I see, I misread that. Still not 4.0 priority though, and also not easy to fix because this becomes a very normal function to the typer...

@Gama11
Copy link
Member Author

Gama11 commented Mar 18, 2019

Agreed, doesn't seem urgent.

@Gama11
Copy link
Member Author

Gama11 commented Apr 8, 2019

Worryingly, a return also seems to bypass the missing this = value check.

class Main {
	public static function main() {
		new Test(0);
	}
}

abstract Test(Int) from Int {
	public function new(i:Int):Void {
		return i; // compiles!
	}
}

I'm not sure what the implicaitons of this are, but that might make it Haxe 4 priority after all?

It at least seems to break with inline, which results in a confusing Cannot inline a not final return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants