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

Suggestion for abstract casts for functions #5857

Closed
kevinresol opened this issue Dec 3, 2016 · 1 comment
Closed

Suggestion for abstract casts for functions #5857

kevinresol opened this issue Dec 3, 2016 · 1 comment
Milestone

Comments

@kevinresol
Copy link
Contributor

kevinresol commented Dec 3, 2016

package;

class Main {
	static function main() {
		var e:Expr = function(e) return 1; // doesn't compile
	}
}

abstract Expr(String) from String to String {
	@:from
	public static function ofInt(i:Int):Expr
		return Std.string(i);
	@:from
	public static function ofFunc(f:Expr->Expr)
		return f('bar');
}

I wish it would work somehow like the below:
Compiler sees it is trying to cast Unknown->Int to Expr. While the compiler search down the @:from list for compatible casts, if it sees 1-argument function cast with non-identical type signature, don't skip right away but try to cast each of the arguments and return type accordingly
i.e. Unknown to Expr & Int to Expr respectively. If all the casts succeed, use that cast.

@Simn Simn modified the milestone: 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Design Apr 17, 2018
@Simn
Copy link
Member

Simn commented Jun 5, 2020

I never really looked at this issue and now that I am looking at it I don't understand it. Sounds like some black magic, so whatever you want to do here would require a haxe-evolution.

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

No branches or pull requests

2 participants