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

Allow & Dynamic<T> #10454

Closed
wants to merge 2 commits into from
Closed

Allow & Dynamic<T> #10454

wants to merge 2 commits into from

Conversation

Simn
Copy link
Member

@Simn Simn commented Oct 29, 2021

Allows this:

typedef KnownDynamic<T> = {known:T} & Dynamic<T>;

function main() {
	var d:KnownDynamic<Int> = { known: 12 };
	d.also = 12;
}

We have this Extend thing for anon_status which I'm using to implement this. In that context, I've noticed that apply_params doesn't recurse into it, which is likely a separate bug.

@RealyUniqueName Could you check this? I might have missed something.

CI failure is unrelated.

closes #9825

@kLabz
Copy link
Contributor

kLabz commented Oct 29, 2021

Could this also [be made to] work with {known:T} & Dynamic / {known:T} & Dynamic<Any>?

This is something that would be very useful for react externs, as components there often accept a well defined list of attributes (props) and also pretty much anything else, that would be transferred to child components or something (that's what you get for asking javascript developers to define some typing rules I guess :P)

@Simn
Copy link
Member Author

Simn commented Oct 29, 2021

Both of these work already.

@kLabz
Copy link
Contributor

kLabz commented Oct 29, 2021

Thanks! Can't wait for 4.3 :P

@R32
Copy link
Contributor

R32 commented Oct 29, 2021

What if there is a typo error? The compiler doesn't seem to remind you

var d:KnownDynamic<Int> = { knowm: 12 };  // typo

@Simn
Copy link
Member Author

Simn commented Oct 29, 2021

That errors with Object requires field known.

| None ->
extends_dynamic := Some t;
| Some _ ->
display_error ctx "Can only extend one Dynamic<T>" p
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check if current T is not compatible with the one stored in extends_dynamic?
Theoretically multiple Dynamic<T> could get into tl from different sources.

@RealyUniqueName
Copy link
Member

It seems this kind of signatures would have issues when both A and B extend Dynamic<T> depending on the case if Ts are different or not.

//@:generic
function unite<A,B,C:A&B>(a:A, b:B):C;

@Simn
Copy link
Member Author

Simn commented Oct 29, 2021

Hmm, I expected unification to handle that case already, but it looks like it doesn't do anything with Extend anons at all. Which makes me wonder why the thing even exists...

@Simn
Copy link
Member Author

Simn commented Nov 1, 2021

I found this: #3228

This means that the Extend status is purely informative, which makes my approach here insufficient.

@Simn
Copy link
Member Author

Simn commented Jan 4, 2022

This approach isn't good so I'll close this for now.

@Simn Simn closed this Jan 4, 2022
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.

Dynamically named field on extern
4 participants