Closed
Description
In Dart 2 I am seeing infos about some typing (uses_dynamic_as_bottom
) and I don't know how I would get around it.
Basically I have something like:
new A()
..func = (int a) {};
Where A.func is of typeFunction(dynamic a)
If I make it Function(Object a)
then it becomes an error:
"A value of type '(int) → Null' can't be assigned to a variable of type 'Function(Object) → dynamic'."
I put together a dartpad of a few things to try and make something work and clarify some rules for myself, but I couldn't find a way to make inline functions like that work.
https://dartpad.dartlang.org/22a4849f9f0d2fcd3813024df252adf0
Thanks!
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
vsmenon commentedon Sep 25, 2017
We took a mis-step here. Our intent is to make
dynamic
in your example work likeObject
- i.e., a static error.Details here:
#29630
jacehensley-wf commentedon Sep 25, 2017
Oh okay, that makes sense. So should I type the parameters to
Null
?vsmenon commentedon Sep 25, 2017
For
A.func
? I think that would work.@leafpetersen
leafpetersen commentedon Sep 26, 2017
Making
A.func
typed to takeNull
will allow any unary function to be assigned to it. Note though that you will need to cast it to a different function type (or use a dynamic call) to call it then with anything exceptNull
. That is:jacehensley-wf commentedon Sep 26, 2017
That shows as an unnecessary cast info
So is there no "bottom" type that isn't null? Something like "Anything"? Because typing the parameter to
Object
doesn't work and neither doesdynamic
.leafpetersen commentedon Sep 26, 2017
Bug. Filed it here #30897 .