Skip to content

Type objects with NNBD #573

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

Closed
lrhn opened this issue Sep 12, 2019 · 1 comment
Closed

Type objects with NNBD #573

lrhn opened this issue Sep 12, 2019 · 1 comment
Labels
nnbd NNBD related issues

Comments

@lrhn
Copy link
Member

lrhn commented Sep 12, 2019

On top of equality (#444), we also need to decide on type literal semantics and the toString behavior of Type objects for NNBD.

A legacy library may expect (<T>()=>T)<int>().toString() to return int. However the actual type is int*. That suggests that we should not put the * into the toString of legacy types.

We can either say that we never include *, or that we only include * when a non-legacy type is part of the type represented by the Type object. That is, the toString of List<int*>* is "List<int>", but the toString of List<int*>? is "List<int*>?".

It's still possible to have different types with the same toString, the types List<int> and List<int*>* would both give List<int> as toString. That is unavoidable unless we mark non-nullable types (say with !), but we do not want that in the long run.

(The option of simply removing Type.toString and making it always return [Instance of Type] is probably too breaking, even if it would be great).

We could also add nnbdTypeToString() to Type which includes all annotations and make toString return the "legacy" toString. Not particularly good design. Or give Type.toString a parameter which makes it return an NNBD string instead of a legacy string. That would need a later migration to switch the default of that parameter, so that we can eventually remove it when removing NNBD-legacy mode completely.

Another question is what type a type literal represents.

  • int should represent non-nullable intin an NNBD-enabled library. That's the only future-proof value. What should int represent in a NNBD-legacy library? Likely int*. Then we are back to Equality of Type objects with NNBD types. #444 because it might be confusing if the two are not equal.

  • Assume a class like class C<T extends C<T>> {}.Then C as a type literal will trigger instantiate-to-bounds. Should instantiate-to-bounds be computed in the declaring or referring library, which may matter if one is NNBD and the other is legacy. Assuming the declaring library is NNBD-enabled the computed (super-)bound is C<dynamic>. Will the type literal in the legacy library be C<C<dymamic>>* or C<C<dynamic>*>*...? (since dynamic* is probably equivalent to dynamic),

@lrhn lrhn added the nnbd NNBD related issues label Sep 12, 2019
@leafpetersen
Copy link
Member

Closing this as a duplicate of #444 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nnbd NNBD related issues
Projects
None yet
Development

No branches or pull requests

2 participants