-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer rejects tests/language_2/generic_methods_generic_function_result_test.dart #30207
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
Comments
@leafpetersen Can you confirm that this is an error? |
The first error is correct, at least that it is an error. To put T foo<T extends num>(int i, T t) <: T Function<T extends num>(S, T) Note that all of the To show this, we must show that The error doesn't print the generic parameters on the types though, which doesn't seem ideal. |
The second error is, I believe a repeat of the first for the second occurence of |
The third error looks incorrect. The inferred type of At the point of the application of |
Thanks Leaf! I also realize that the comment is wrong. It should be |
cc @jmesserly |
fyi #29778 is a possibly related substitution problem |
The test should actually be rejected at compile-time because it uses a generic function type as an actual type argument (at all), not because of any particular missing subtype relationships. We have the following in the informal spec of the new inline function types, which is the construct that introduces support for specifying the type of a generic function: 'It is a compile-time error if a generic function type is used as a bound for a formal type parameter of a class or a function. It is a compile-time error if a generic function type is used as an actual type argument'. Issue #29484 provides more background. |
I do not think any of these restrictions apply to this test. No generic function type is used as bound or as type argument. Here is the source of the test to avoid confusion: import "package:expect/expect.dart";
T foo<T extends num>(int i, T t) => i + t;
List<T Function<T extends num>(S, T)> bar<S extends int>() {
return <T Function<T extends num>(S, T)>[foo, foo];
}
void main() {
var list = bar<int>();
print(list[0]
.runtimeType); // "<T extends num>(int, T) => T" when reifying generic functions.
Expect.equals(123, list[1]<int>(100, 23));
} |
Ah, right, I completely missed that. @eernstg is correct - we have a predicativity restriction: " It is a compile-time error if a generic function type is used as an actual type argument", so |
Oops, sorry, I see it now. The type argument of List in the return type is a generic function type. |
The test has been updated, but the analyzer fails to report a compile time error in non-strong mode (multi test '01') and wrongly reports a compile time error in strong mode (multi test 'none'). |
merging this into #29778 |
Reopening this. The analyzer correctly reports an error where it should, but, as Leaf had said:
This is still an issue in the test |
SG |
The errors reported by the analyzer for tests/language_2/generic_methods_generic_function_result_test.dart does not look correct.
ERROR|STATIC_WARNING|LIST_ELEMENT_TYPE_NOT_ASSIGNABLE|/b/build/slave/azrs-be/build/sdk/tests/language_2/generic_methods_generic_function_result_test.dart|14|44|3|The element type '(int, T) → T' can't be assigned to the list type '(S, T) → T'.
ERROR|STATIC_WARNING|LIST_ELEMENT_TYPE_NOT_ASSIGNABLE|/b/build/slave/azrs-be/build/sdk/tests/language_2/generic_methods_generic_function_result_test.dart|14|49|3|The element type '(int, T) → T' can't be assigned to the list type '(S, T) → T'.
ERROR|STATIC_WARNING|ARGUMENT_TYPE_NOT_ASSIGNABLE|/b/build/slave/azrs-be/build/sdk/tests/language_2/generic_methods_generic_function_result_test.dart|21|35|3|The argument type 'int' can't be assigned to the parameter type 'S'.
The text was updated successfully, but these errors were encountered: