Skip to content

Small-features-21Q1 fix: Allow generic functions as bounds #1445

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

Merged
merged 1 commit into from
Feb 12, 2021

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Feb 9, 2021

The small-features-21Q1 spec includes the feature described in #496, except that it does not mention generic function types used as bounds. I think we should include bounds: There is a need to specify a generic function type as a bound if a particular type variable is intended to have a value which is a generic function type, e.g., in order to know how many type arguments to pass in invocations.

class C<F extends void Function<X>(X)> {
  F f;
  C(this.f);
  void m() { f<int>(42); }
}

class D<F extends void Function<X>(X, [List<X>?]) extends C<X> {...}

Also, this PR fixes a typo tripple-shift --> triple-shift.

@eernstg eernstg requested a review from lrhn February 9, 2021 09:13
@google-cla google-cla bot added the cla: yes label Feb 9, 2021
@eernstg
Copy link
Member Author

eernstg commented Feb 12, 2021

@lrhn, do you wish to omit the bounds from #496?

@lrhn
Copy link
Member

lrhn commented Feb 12, 2021

No, I want to allow all types everywhere, as arguments and as bounds.

It gets problematic otherwise: foo<F extends Function, G extends F>(){} with foo<T Function<T>(T), Never Function<T>(Object?)>() would either be a run-time type error because the bound is a generic function type, or it would always be a compile-time error to use a type variable as bound unless it cannot possibly be bound to a generic function type (so not an unbounded type variable, and not one bounded by Function, Object, FutureOr<Object>, or similar supertypes of generic function types).

Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

@eernstg eernstg merged commit 814bb1a into master Feb 12, 2021
@eernstg eernstg deleted the small_features_typo_feb21 branch February 12, 2021 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants