-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Instantiate-to-bounds process produces different results depending on the nesting level of type variable for function return value. #33606
Comments
The instantiate-to-bounds gives you an actual type of dynamic Function() Function() Function() aka The assignments of The assignment of I'm guessing the strong-mode type system is extra strict here because it knows the exact type of All-in-all, I think this works correctly. |
If so, should not instantiate-to-bounds check stops on the second level? |
The return type of You are assigning |
Agreeing completely with @lrhn, I believe the topic here is exact types, that is #33307, and the rest is just a matter of subtyping relationships for which I believe we have no ambiguity or novelty here. Adding a reference to this issue in #33307. So given that it works as intended (relying on exact types to be resolved elsewhere), I guess we could close this issue; or do you, @lrhn or @iarkh, see anything here beyond that? |
Oh, one thing!: In tests, we should take care to avoid disturbances introduced by the not-so-well-defined approach to exact types. That is, when we have Cases that involve exact types would then exist in addition to the 'pure' test cases, or maybe the "exact cases" should be commented out until we have a clear approach to exact types, but we should at least cover the case where no exact types are involved as the primary ones. Note that exact types play a role for downcasts (i.e., the downcast variant of assignability), but they do not matter for upcasts, so there is no need to write extra code to eliminate the exact type unless there is a downcast. |
I'd like to resolve this issue. Checking again, we get exactly the errors that we would expect based on a traditional subtype requirement (that is, the 4 deeply nested cases in the second example of the initial text of the issue are flagged as errors): The downcasts are flagged and the upcasts (including the "same-type-casts" that we have with This means that there is nothing in this issue which is concerned with instantiate-to-bound or with function types that shows any unexpected behavior, and hence we should just close this issue. The area where we do need clarification is in the use of exact types (we only get an error in all four cases of the second However, I do not think that we should use this issue to clarify exact types, we already have #33307 for that. Under the assumption that it is OK for So I'll close this issue now; this issue is still mentioned in #33307 as yet another example of a situation where exact types play a role, but we already have other references to such issues which are closed and which contain yet another example, so that's not a problem. |
The following source code describes parametrized function type via
typedef
(return value should have parameter type) and that try to assign some function to variable of the given type:This passes for me, both dart and dart analyzer don't produce any errors or warnings here.
However, if I increase the nesting level when declare variables, both dart and analyzer starts to fail:
Looking into Instantiate-to-Bounds Spec, it seems like at least all cases like
F<F<F<F...<F<dynamic>..>>>>
should pass.Sample output is:
$>dartanalyzer ttt.dart
Analyzing ttt.dart...
error - The function 'testme' has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → dynamic'. This means its parameter or return type does not match what is expected at ttt.dart:5:19 - strong_mode_invalid_cast_function
error - The function 'testme' has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → dynamic'. This means its parameter or return type does not match what is expected at ttt.dart:6:28 - strong_mode_invalid_cast_function
error - The function 'testme' has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → () → dynamic'. This means its parameter or return type does not match what is expected at ttt.dart:7:22 - strong_mode_invalid_cast_function
error - The function 'testme' has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → () → dynamic'. This means its parameter or return type does not match what is expected at ttt.dart:8:31 - strong_mode_invalid_cast_function
hint - The value of the local variable 'f6' isn't used at ttt.dart:5:14 - unused_local_variable
hint - The value of the local variable 'f7' isn't used at ttt.dart:6:23 - unused_local_variable
hint - The value of the local variable 'f8' isn't used at ttt.dart:7:17 - unused_local_variable
hint - The value of the local variable 'f9' isn't used at ttt.dart:8:26 - unused_local_variable
4 errors and 4 hints found.
$>dart ttt.dart
ttt.dart:5:19: Error: The top level function has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → dynamic'.
Change the type of the function or the context in which it is used.
F<F<F>> f6 = testme;
^
ttt.dart:6:28: Error: The top level function has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → dynamic'.
Change the type of the function or the context in which it is used.
F<F<F<F>>> f7 = testme;
^
ttt.dart:7:22: Error: The top level function has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → () → dynamic'.
Change the type of the function or the context in which it is used.
F<F<F<F>>> f8 = testme;
^
ttt.dart:8:31: Error: The top level function has type '() → () → () → dynamic' that isn't of expected type '() → () → () → () → () → dynamic'.
Change the type of the function or the context in which it is used.
F<F<F<F<F>>>> f9 = testme;
^
$>dart --version
Dart VM version: 2.0.0-dev.64.1 (Thu Jun 21 08:47:55 2018 +0200) on "windows_x64"
$>
The text was updated successfully, but these errors were encountered: