-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fixes #2383. Add more constant evaluation tests #2396
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I was a little bit worried that the tests in LanguageFeatures/Extension-types/static_analysis_extension_types_A20_t02.dart would be duplicates of language tests that Lasse has added (or is about to add) to $SDK/tests/language/...
, but we should in any case check all combinations so I listed a few that I couldn't find currently.
For the function test we'd probably need yet another test library: The current one is fine, but it doesn't test the processing of parameter types.
In particular, we should verify that types like void Function(int)
and void Function(ExtInt1)
and void Function(ExtInt2)
are identical as constants. The reason why this is important is that the canonicalization of function types might use different parts of the implementation to reduce void Function(ExtInt1)
to void Function(int)
than the parts that we have already exercised with the other tests in this PR.
However, this additional test could certainly be a separate PR, if that's more convenient.
On the other hand, it's probably not important to have additional cases where the function types are nested in other types (that is, tests about Map<ExtFuncInt, ...>
and such), because we have tested in the previous test that processing of Map<..., ...>
does reach the type arguments. So if the function types work as the outermost part of a type then they probably also work as type arguments of Map
. So it's fine that we have List<List<ExtFuncInt>>
in a test here, but there's no need to expand on this kind of type in the new test.
But one function type as a subterm of another function type is a case that we need to cover.
I also think it's important that we express those types as function types directly: It is probably going to exercise different locations in the implementation when it handles void Function([ExtInt1])
vs. void Function([int])
, compared to the situation where it handles F<ExtInt1>
vs. F<int>
where typedef F<X> = void Function([X]);
.
So we might have a test that succeeds using F
, but the test that contains the function types written out in full might still fail.
In summary, for this PR I think we just need to add a few cases that are missing, and then it's a different PR that adds a bunch of extra function type tests.
LanguageFeatures/Extension-types/static_analysis_extension_types_A20_t02.dart
Show resolved
Hide resolved
Oops, I forgot one thing: Assuming the following declaration: typedef T GenFunction<T>();
Edit: ".. a different way to produce the type |
@eernstg why I'm going to add all missing parts (including parametrized function types) to this PR if ypu don't mind |
A generic function type is the type of a function that accepts one or more actual type arguments at each invocation. For instance, The old-style type alias declaration cannot declare a generic function type, it can only declare a family of non-generic function types where each reference to the type alias must provide actual type arguments (or they will be selected using instantiation to bound). In order to declare a generic function type using a type alias, use the new syntax: |
OK! |
@eernstg is Ok that we have no error for typedef T GenFunction1<T>(T t);
typedef GenFunction2<T> = T Function<T>(T t);
extension type const ExtFuncGen1<T>(GenFunction1<T> _) {} // Error: An extension type parameter can't be used non-covariantly in its representation type.
extension type const ExtFuncGen2<T>(GenFunction2<T> _) {} // No error |
Yes, that's OK: The type parameter typedef GenFunction2<T> = X Function<X>(X t); |
Updated. Please take another look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I forgot where it is, but I think we don't cover canonicalization of function types where extension types occur as subterms. So we can do it here or in a separate PR, whatever fits best for you.
LanguageFeatures/Extension-types/static_analysis_extension_types_A20_t04.dart
Outdated
Show resolved
Hide resolved
Updated. Please take another look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
2023-12-07 sgrekhov22@gmail.com Fixes dart-lang/co19#2413. Add missing expected compile-time errors for CFE (dart-lang/co19#2418) 2023-12-07 sgrekhov22@gmail.com dart-lang/co19#2119. Run dart formatter on LibTest/async tests (dart-lang/co19#2417) 2023-12-06 sgrekhov22@gmail.com dart-lang/co19#2398. Make asyncStart/End() safe in LibTest/async (dart-lang/co19#2416) 2023-12-06 sgrekhov22@gmail.com Fixes dart-lang/co19#2355. Add more typed_date.setRange() tests (dart-lang/co19#2412) 2023-12-06 sgrekhov22@gmail.com dart-lang/co19#2404. Small code-style improvements and description update (dart-lang/co19#2414) 2023-12-04 sgrekhov22@gmail.com dart-lang/co19#2004. Add deferred libraries tests according to the changed spec (dart-lang/co19#2411) 2023-12-04 sgrekhov22@gmail.com Fixes dart-lang/co19#2383. Add more constant evaluation tests (dart-lang/co19#2396) Change-Id: I15e0d681538fa0f2a311f74d1930fad7270b81a0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340561 Commit-Queue: Alexander Thomas <athom@google.com> Reviewed-by: Erik Ernst <eernst@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
No description provided.