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

@:structInit can be used to bypass final assignment #10017

Open
Gama11 opened this issue Dec 20, 2020 · 0 comments
Open

@:structInit can be used to bypass final assignment #10017

Gama11 opened this issue Dec 20, 2020 · 0 comments

Comments

@Gama11
Copy link
Member

Gama11 commented Dec 20, 2020

Putting @:structInit on a child class auto-generates a constructor that doesn't initialize the final fields of the base class, which seems unsound:

function main() {
	final child:Child = {s: ""};
	trace(child.i); // undefined
}

class Base {
	public final i:Int;

	public function new(i:Int) {
		this.i = i;
	}
}

@:structInit class Child extends Base {
	public final s:String;
}

If Base is itself a @:structInit class without an explicitly declared constructor, you get the compile-time error you would probably expect:

source/Main.hx:3: characters 23-30 : Object requires field i
@Gama11 Gama11 changed the title @:structInit can be used to bypass final constraints @:structInit can be used to bypass final assignment Dec 20, 2020
@RealyUniqueName RealyUniqueName added this to the Bugs milestone Dec 22, 2020
@Simn Simn modified the milestones: Bugs, Later Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants