Skip to content

Conversation

@tobil4sk
Copy link
Member

This fixes #9990, which crashes due to a missing TODATAARRAY instruction, which is required to convert the resulting dynamic array back into an int array.

Before:

3	30				CALLSUPER 1  1 1 
3	30					CALLSTATIC 5  6 1 
3	30						TODYNARRAY 
3	30							VAR 6681

vs after:

3	30				CALLSUPER 1  1 1 
3	30					TODATAARRAY 2 
3	30						CALLSTATIC 5  6 1 
3	30							TODYNARRAY 
3	30								VAR 6681

I imagine the same issue can occur with other types of calls, so I will look into that before marking this as ready.

Some of those (* TODO - proper re-typing *) comments also look a bit worrying...

@tobil4sk
Copy link
Member Author

Indeed, we have the same error with super constructor calls, which requires are not covered by the current patch:

// template function converts to dynamic array
function wrap<T>(a:Array<T>):Array<T> {
	return a;
}

class Parent {
	public function new(a:Array<Int>) {
		a.copy();
	}
}

class Child extends Parent {
	public function new(a:Array<Int>) {
		super(wrap(a));
	}
}

function main() {
	new Child([1,2,3]);
}

@Aidan63 I'm hoping you might have some insight into the cpp generator since you refactored it not long ago. Any chance you might know what the best solution here is? I'm confused with the difference between CppFunction ((FuncSuperConstruct ...)) and CppSuper, or why the former is not currently handled... 😅

@Aidan63
Copy link
Contributor

Aidan63 commented Jul 21, 2025

Some of the retypers logic can be a bit difficult to follow.

CppSuper is any occurance of super, the TField retyping deals with CppSuper by turning them all into CppFunction FuncSuper as if the left hand side of a TField expression is super it can't be a super constructor call so can safely be considered a class member function super call.
When retyping TCall if it comes across a CppSuper then it it can safely assume it's a super constructor since any member function supers will have been retyped by this point using the above logic, so they become CppFunction FuncSuperConstructor.

CppFunction is any reference to a function, e.g. final c = foo where foo is a function would result in the right hand side of the assignment operator become a CppFunction. You can't do anything with super other than directly call it so any CppFunction involving supers will be with a CppCall.

I interpreted those "todo proper retyping" comments to refer to the args being retyped to TCppDynamic instead of using the arguments type, I've changed that as part of this PR https://github.com/HaxeFoundation/haxe/pull/11981/files#diff-78f353b143a52df58c7c9980eb2f3801f33f84484509ed02009a448182a3b8a4L735

There could well be some missing conversions for cppia in here, I can take a closer look if need be.

@skial skial mentioned this pull request Aug 4, 2025
1 task
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.

[cppia] Weird exception on Array.copy involving super calls

2 participants