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

Abstract multitype value that is generic does not generate correctly in 4.3.4 #11676

Closed
Oxdeception opened this issue May 25, 2024 · 4 comments
Closed

Comments

@Oxdeception
Copy link

Online example

Minimal Example:

class Main {
    static function main() {
        var comp = new AComponent([1,2,3]);
        trace(comp.doSomething());
    }
}

interface Component<T> {
	function doSomething():T;
}

@:forward
@:multiType
abstract AComponent<T>(Component<T>) {
	public function new(value:T);

	@:to public static inline function toInt(t:Component<Int>, value:Int):IntComponent {
		return new IntComponent(value);
	}

	@:to public static inline function toIntArray(t:Component<Array<Int>>, value:Array<Int>):ArrayComponent<Int> {
		return new ArrayComponent(value);
	}
}

@:generic
@:remove
class ArrayComponent<T> implements Component<Array<T>> {
	final value:Array<T>;

	public function new(value:Array<T>) {
		this.value = value;
		var x = [];
		for (i in 0...value.length) {
			var y = new AComponent(this.value[i]).doSomething();
			x.push(y);
		}
	}

	public function doSomething():Array<T> {
		return this.value;
	}
}

class IntComponent implements Component<Int> {
	final value:Int;

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

	public function doSomething():Int {
		return value;
	}
}

Under 4.3.4 this causes a Not_found error when generating C++, CPPIA, and JVM.
Neko, SWF, Python, HashLink, and JavaScript will compile and hit runtime errors.

The example will work correctly with when using 4.3.3, with the exception of HashLink

Ensuring that the AComponent is assigned to a variable before using it apparently resolves the issue Online example

@kLabz kLabz added this to the 4.3 Hotfix candidates milestone May 25, 2024
@kLabz kLabz self-assigned this May 28, 2024
@kLabz
Copy link
Contributor

kLabz commented May 28, 2024

Additional notes regarding hl:

| Haxe version | Analyzer off                                     | Analyzer on                                      |
| ------------ | ------------------------------------------------ | ------------------------------------------------ |
| 4.3.4        | ok                                               | segfault (`IntComponent.doSomething`)            |
| 4.3.3        | segfault (`$ArrayComponent_Int.__constructor__`) | segfault (`$ArrayComponent_Int.__constructor__`) |

Eval:

[0] Instance constructor not found: _Test.AComponent_Impl_

@kLabz
Copy link
Contributor

kLabz commented May 28, 2024

Caused by b00bca0

Other error on hl is unrelated (edit: hmm, maybe not really unrelated), will need to investigate

@kLabz kLabz removed their assignment May 28, 2024
@kLabz
Copy link
Contributor

kLabz commented May 28, 2024

@Simn do you have any idea what could be done here without breaking #11526? :/

@Simn
Copy link
Member

Simn commented May 28, 2024

Likely somewhere in handle_abstract_casts, but I'll have to take a closer look to provide more useful information.

@Simn Simn closed this as completed in 2106be4 Jun 12, 2024
kLabz pushed a commit that referenced this issue Jun 28, 2024
@kLabz kLabz mentioned this issue Jul 18, 2024
kLabz pushed a commit that referenced this issue Jul 18, 2024
@kLabz kLabz removed this from the 4.3 Hotfix milestone Jul 18, 2024
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