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

Static extensions vs. constrained monomorphs #9554

Closed
Simn opened this issue Jun 10, 2020 · 2 comments
Closed

Static extensions vs. constrained monomorphs #9554

Simn opened this issue Jun 10, 2020 · 2 comments

Comments

@Simn
Copy link
Member

Simn commented Jun 10, 2020

using Main;

class Main {
	static public function main() {
		var obj = merge({foo: 12}, {bar: "bar"});
		obj.staticExtension();
	}

	static function merge<A:{}, B:{}, C:A & B>(a:A, b:B):C {
		return null;
	}

	static function staticExtension(a:{foo:Int, bar:String}) {}
}
source/Main.hx:6: characters 7-22 : Unknown<0> : { foo : Int, bar : String } has no field staticExtension

This is probably just a missing using_field in the TMono code path of type_field.

@Simn Simn self-assigned this Jun 10, 2020
@Simn
Copy link
Member Author

Simn commented Jun 10, 2020

I thought I found a regression with code like this:

using Main;

class Main {
	static public function main() {
		infer({foo: 12});
	}

	static function infer(a) {
		a.foo = 12;
		a.staticExtension();
	}

	static function staticExtension(a:{foo:Int}) {}
}
source/Main.hx:5: characters 9-18 : Object requires field staticExtension
source/Main.hx:5: characters 9-18 : For function argument 'a'

But that was failing before as well. I guess it makes sense that it does.

However, completion shows staticExtension as a field on a, so there's some discrepancy here.

@frabbit
Copy link
Member

frabbit commented Oct 22, 2021

It would be great to have this working:

static function merge<A:{}, B:{}>(a:A, b:B):A & B {
		return null;
	}

It's different to the constraint C Example, because C opens the type on the call side which means 

var x: { foo: Int, bar: Int, ohno: Int } = merge({ foo: 1}, { bar: 2});

compiles just fine.

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

2 participants