-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
questions about CheckedDict and unknown types #71
Comments
Hi Ben, At first glance these do look like bugs. CheckedDict with dynamic key or value should translate to object at runtime (though not in the compiler; object and dynamic are quite different there in terms of what we'll allow you to do with values pulled out.) I'll hopefully get a fix up for this soon. Thanks as always for the report! |
Ok, this turns out to be kind of a nasty issue. The This is a hard problem to resolve, particularly for the nonstatic code case, because there's no way nonstatic code at runtime can know which "types" are resolved to dynamic by the static compiler. We have two ideas of broad directions for fixing this. The ideal fix would require the runtime classloader and the static compiler to share a source of truth for which types are known by the static compiler and which are resolved to A more partial "fix" (that still wouldn't bring great UX) could look something like this: First we fix the static compiler to actually emit Second, we require creation of checked dicts in nonstatic code to use a type alias like that one, imported from a static module. This will ensure the static compiler is always in charge of creating CheckedDict types, and can ensure they are consistent. The exact method for disallowing nonstatic modules from creating new CheckedDict generic types remains TBD: could use compiler tricks to ensure that The shared source of truth option is definitely better if we can make it work. Since this is a UX issue, not a soundness issue, and it's not a UX issue that affects low-touch conversions of non-static code, we likely aren't going to prioritize addressing it immediately. |
One other note: the second part of the issue ( I think in this specific case we could technically relax the invariance and allow the assignment, since both |
For the first part, does the runtime need to throw an error for (That definitely won't fix the issue with nonstatic types getting used as keys/values, but I thought it'd be enough for |
I guess that's a judgment call, but I think it would be kind of confusing to allow just anything at all (e.g. It's a good point though that short of fully fixing the bug, we could easily whack-a-mole a few specific common cases by explicitly resolving them to |
IIUC (based on issue 59), types like
CheckedDict[str, Set[str]]
where SP doesn't understand part of the type should:CheckedDict[str, object]
But neither seems to work. (I'm running SP commit 1b01cd8.)
First, this type doesn't work except in a constructor call. Other type annotations give an error:
Second, the constructor call gives a
chkdict[str, dynamic]
instead of replacing the unknown type withobject
:Are these problems?
The text was updated successfully, but these errors were encountered: