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

[java/cs] @:structInit does not work on extended class #6078

Closed
kevinresol opened this Issue Mar 7, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@kevinresol
Contributor

kevinresol commented Mar 7, 2017

Revision: 84bf7e5

class Main {
	
	static function main() {
		var foo:Foo = {bar: 1};
		trace(foo);
	}
}

@:structInit
class Foo extends Bar {}

class Bar {
	var bar:Int;
	public function new(bar:Int) {
		this.bar = bar;
	}
}

Compiling this in java/cs fails with some weird error: { bar : Int } has extra field bar
But fine in other targets

@Simn Simn modified the milestone: 4.0 Mar 20, 2017

@nadako

This comment has been minimized.

Member

nadako commented Mar 29, 2017

Eh, isn't that a pre-generation error?

@nadako

This comment has been minimized.

Member

nadako commented Mar 29, 2017

Looks like get_constructor behaves differently and returns a constructor with no arguments, huh.

@frabbit

This comment has been minimized.

Member

frabbit commented Nov 20, 2017

for java/c# the function check_struct_init_constructor branches into the None case which generates a new constructor based on the fields of the current type, which doesn't check the super type at all. For Neko/Eval the function branches into the Some case, i guess in that case the constructor is already a copy of the superclass, which of course works.

@frabbit

This comment has been minimized.

Member

frabbit commented Nov 21, 2017

it's exactly this line https://github.com/HaxeFoundation/haxe/blob/development/src/typing/typeload.ml#L2897
which causes this issue, the constructor is not generated for pf_overload platforms. Inside of check_struct_init_constructor it's generated but the super constructor is not reused.

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