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

[hxb] Unbound type parameter issues #11628

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft

Conversation

kLabz
Copy link
Contributor

@kLabz kLabz commented Apr 4, 2024

Added failing tests with currently identified issues:

Local function type parameter vs @:generic

class Main {
	static function main() {
		function foo<T>(arr:Array<T>) sortDesc(arr);

		foo([""]);
		foo([42]);
	}

	@:generic
	public inline static function sortDesc<T>(array : Array<T>) {}
}

Warning : (WUnboundTypeParameter) Unbound type parameter foo.T

Not sure how that one should behave; if that's not supposed to be supported, it should at least error/warn properly. Note that this doesn't really break.

Anon field type parameter in abstract underlying type

typedef Foo = {
	function get<TField>():Null<TField>;
}

abstract HaxeMemento(Foo) {
	public function getInner<TAbstract>():Null<TAbstract> {
		return this.get();
	}
}

Here, first compilation is fine, second gives an unbound type parameter warning, and third crashes.
Crash avoided in 0e96fae

@skial skial mentioned this pull request Apr 9, 2024
1 task
@kLabz kLabz added this to the 5.0 preview 1 milestone Apr 29, 2024
@kLabz kLabz force-pushed the hxb_unbound_ttp_issues branch 2 times, most recently from 24a5d0e to 24b4599 Compare May 14, 2024 12:52
@kLabz
Copy link
Contributor Author

kLabz commented May 14, 2024

I could dodge the crash by adding TPHUnbound that represents the "error state" so that next compilation doesn't hit a Dynamic that triggers the crash by not pulling the local context.

I'm not really fond of that patch, but it makes things a bit better for such cases.

As for the actual unbound type parameter warnings here (which still make the tests fail as they currently expect no output), I'm not sure what to do. They do seem like actual unbound type parameters, which would mean current result is fine? 🤔

@Simn
Copy link
Member

Simn commented May 14, 2024

Yes I don't think there's a hxb-specific problem here, it's likely all related to #3033.

@kLabz
Copy link
Contributor Author

kLabz commented May 14, 2024

What about that TPHUnbound patch? Should I add it to development to avoid crashes?

@Simn
Copy link
Member

Simn commented May 14, 2024

Seems a bit strange but if it helps temporarily then I don't mind.

kLabz added a commit that referenced this pull request May 15, 2024
@kLabz
Copy link
Contributor Author

kLabz commented Jul 21, 2024

#4599 (comment)

One solution for this might be to allow partial generic expansion. Basically, if we substitute a generic type parameter with a non-generic one, we absorb that type parameter into the new function and make the function @:generic again.

This would require reapplying calls to generic functions, but I think this is exactly the same situation as overload calls for which we already do that anyway.

Is that what we need for first case here?

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

Successfully merging this pull request may close these issues.

2 participants