Skip to content

Fix typing of new #6097

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

Merged
merged 3 commits into from
Mar 19, 2019
Merged

Fix typing of new #6097

merged 3 commits into from
Mar 19, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 17, 2019

Assume

   class C[X]
   type A[X] = C[X]

The previous rule for new A overwrote the type of A
with C, in order to satisfy the condition that the type
of new should be a class type. Overwriting types like
that in Typer is wrong, since it is not preserved by pickling.
We tried to patch up things in RefinedPrinter, but this is not
enough, as test case alias-new.scala shows. This test caused
the type in a new to be unpickled as a <notype>.

The fix is to treat eta-reduction in new types in a purely functional
way, applied in both Typer and TypeAssigner.

The problem was encountered when systematically testing creation methods,
but it has nothing to do with them.

Assume
```
   class C[X]
   type A[X] = C[X]
```
The previous rule for `new A` overwrote the type of `A`
with `C`, in order to satisfy the condition that the type
of `new` should be a class type. Overwriting types like
that in Typer is wrong, since it is not preserved by pickling.
We tried to patch up things in RefinedPrinter, but this is not
enough, as test case `alias-new.scala` shows. This test caused
the type in a `new` to be unpickled as a <notype>.

The fix is to treat eta-reduction in new types in a purely functional
way, applied in both Typer and TypeAssigner.

The problem was encountered when systematically testing creation methods,
but it has nothing to do with them.
@odersky
Copy link
Contributor Author

odersky commented Mar 17, 2019

The fix breaks FromTasty tests. i0306.scala first, and once that it blacklisted a bunch of others where the decompiled source is not compilable. Wrt the example above, we'd see new nodes like:

 new ([X] => C[X])[String]

We should leave this as either new A[String] or new C[String], but expanding A alone to
[X] => C[X] does not work. I am not sure where this is done, though. @nicolasstucki can you take a look?

Note: Previously this problem was hidden because we overwrote the alias type A with C in Typer.

odersky added a commit to dotty-staging/dotty that referenced this pull request Mar 17, 2019
... awaiting a fix for scala#6097.
@nicolasstucki nicolasstucki force-pushed the fix-new-alias branch 4 times, most recently from 920a03f to 463b2de Compare March 19, 2019 07:46
@nicolasstucki
Copy link
Contributor

Now i0306.scala passes the tests

@odersky odersky merged commit f59f2ba into scala:master Mar 19, 2019
@allanrenucci allanrenucci deleted the fix-new-alias branch March 19, 2019 18:07
odersky added a commit to dotty-staging/dotty that referenced this pull request Mar 26, 2019
... awaiting a fix for scala#6097.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants