-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer assigns incorrect exact type to set literals #35431
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
FYI @bwilkerson. I've marked it as P1 because it concerns a new feature, but I think it would be ok to wait until the language team decides whether to land dart-lang/language#129 before working on this. |
@lrhn as of c565d4e, the spec has been changed to avoid specific mention of |
@lrhn ping |
I'm not sure what the status of "exact types" is in general (re. #33307). The run-time type of a non-const map literal is a We should do the same thing for Would it be possible for "exact types" to be handled something like:
The static type of a set literal with element type If I can't get this change, then just use |
I don't understand why you say this (you said something similar in the proposal document). Every implementation that I've tested uses "Map" as the static type of literals. This I think works out fine except that you therefore can't write I'm fine with this, and it sounds like you're fine with it as well? If so, I'd suggest we just make that the specified behavior. Otherwise, I don't see any way of getting around making the spec talk about Linked HashMap. (Implicitly, I think the spec has to talk about LinkedHashMap in order to specify the runtime semantics, even if it chooses to refer to it indirectly, but that's another issue). |
@leafpetersen So if I'm understanding you correctly, what you're proposing we implement is:
I would be fine with this; in fact I really like it because AIUI it's what the analyzer currently does! The main reason I've been pushing on this thread is because the other proposals we've entertained have the negative consequence that they would require information about the |
Yes, that is my proposal. |
I'm fine with just using It's slightly icky that I keep assuming that we changed that because I remember some mail thread about it where there was code written like The specification is not trying to avoid mentioning |
I suspect that we don't actually need exact types. What we do need is (1) the regular notion of an OO type where the effect of knowing that an expression In addition to that we can have (2) a notion of "guaranteed failure" of a downcast. When such a guaranteed failure has been established it makes sense to flag the downcast; this could be an error or it could be a warning (there is no threat to soundness, it's only about a dynamic failure which is guaranteed rather than potential). So maybe the right concept would be some kind of predicate: For any given expression This would eliminate the property that we've otherwise struggled with: If an expression (especially a special one like a list/set/map literal) has a type which may be used as the exact type, but we don't really want that specific (secret, platform dependent) type to appear in error messages, then it's tempting to give that expression another "exact type" which flies in the face of that concept; e.g., it just isn't true that the exact type of a map literal is Error messages don't actually have to tell anything other than the static type of an expression and the result from the predicate, it does make sense to say that |
Ok, the static type of Set and Map literals will be resolved as If at a later point we feel that not being able to downcast to |
Closing in accordance with Leaf's comment; under the new decision, the behavior of the analyzer is now considered correct. |
According to
https://github.com/dart-lang/language/blob/master/accepted/future-releases/set-literals/feature-specification.md
, under the heading "Exact Types of Literals":I believe this implies the following behaviors:
However if I feed the above code into the analyzer (passing in
--enable-experiment set-literals
on the command line), it rejects the assignment to s1, sayingThe set literal type 'Set<Null>' isn't of expected type 'LinkedHashSet<Null>'. The set's type can be changed with an explicit generic type argument or by changing the element types
.The text was updated successfully, but these errors were encountered: