Skip to content

[hl] fix return in generic with void parameter - #13046

Open
yuxiaomao wants to merge 4 commits into
HaxeFoundation:developmentfrom
yuxiaomao:dev-hl-generic-void
Open

yuxiaomao wants to merge 4 commits into
HaxeFoundation:developmentfrom
yuxiaomao:dev-hl-generic-void

Conversation

@yuxiaomao

Copy link
Copy Markdown
Contributor

For the following repro:

class Base<T> {
	public function new() {}
	public function call() : T {
		return null;
	}
	public function call2() : T {
		return null;
	}
}

class Sub extends Base<Void> {
	var count = 0;
	override function call() : Void {
		count++;
		if( count == 1 )
			return;
		count++;
	}
	override function call2() : Void {
	}
}

function main() {
	var i : Base<Void> = new Sub();
	i.call();
	i.call2();
}

call fail at hl-check:

 16 |    return;
    |    ^^^^^^
    | Check failure at fun@27 @6 - Register 3(void) should be dyn and not void

and call2 fail as fatal error (probably caused by the 0 opcode function of call2)

Fatal error: exception Invalid_argument("index out of bounds")
Raised by primitive operation at Hlopt.code_graph.op in file "src/generators/hlopt.ml" (inlined), line 463, characters 16-30
Called from Hlopt.code_graph.make_block.loop in file "src/generators/hlopt.ml", line 497, characters 27-33
Called from Hlopt.code_graph.make_block in file "src/generators/hlopt.ml", line 534, characters 3-11
Called from Hlopt.code_graph in file "src/generators/hlopt.ml", line 537, characters 13-28
Called from Hlopt._optimize in file "src/generators/hlopt.ml", line 771, characters 24-36
Called from Hlopt.optimize in file "src/generators/hlopt.ml", line 1113, characters 13-24
Called from Genhl.generate.(fun) in file "src/generators/genhl.ml", line 4399, characters 21-78

This PR try to adresse them by:

  • Generate r:dyn (or whatever ctx.m.mret is), ONull r, ORet r instead of r:void, ORet r for the middle return;.
  • Treat an empty block as not having a final return (I think the name have_final_jump is misleading, maybe it's something like need_final_return)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant