Skip to content

Fix #1907: Improve error message #1921

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 10 commits into from
Feb 8, 2017
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 1, 2017

Two fixes:

  • we avoid the 5-levels of array tag by synthesizing array tags at the same time as other class tags
  • we bail when asked to generate a ClassTag[Nothing] or ClassTag[Null].

The second point is likely contentious. It does forbid some programs that would make sense such as

def f(x: Any) = ???
f(Array(): _*)

But it also avoids many situations that would lead to surprising results or confusing errors later.

@retronym What is your take on this?

The previous condition for caching companionRefs contained a condition

    result.companionRefs.forall(implicitScopeCache.contains)

which was always false because we cache types in `implicitCodeCache`, not
companion refs. The new logic fixes this and does not need a second traversal
because it is integrated in `iscopeRefs`.
When printing info about adding to constraints, show the hashes
of the typerstate stack, so that we know where constraints are added.
The test exercises all the improvements made in previous
commits of this branch.
The previous implicit definition of arrayTag in DottyPredef
priorities arrayTag over all other classtag searches, which
led to surprising results in `i1907a.scala`.
It seems in most cases this leads to weird behavior and cause
confusing error messages later.

It also means we cannot create an Array[Nothing], except by
passing the classtag explicitly.
@odersky
Copy link
Contributor Author

odersky commented Feb 1, 2017

This is based on #1918. Only the last 3 commits are new. The contentious commit about not synthesizing ClassTags of bottom types is e34555f.

@retronym
Copy link
Member

retronym commented Feb 1, 2017

I'll need to page this back in to comment meaningfully, but for now, I'll dump some links to related discussions about soundness issues with arrays and/or class tags of bottom types:

https://issues.scala-lang.org/browse/SI-9754
https://issues.scala-lang.org/browse/SI-5353
https://issues.scala-lang.org/browse/SI-7453

Updated with SI issues reported by Jason
@odersky
Copy link
Contributor Author

odersky commented Feb 1, 2017

@retronym Thanks for the links. They are all treated OK under this commit. I am not sure whether they would have been soundness issues before, since dotc with its union types behaves differently than scalac. So for instance i1907.scala is compiled by scalac but rejected by dotc.

@smarter
Copy link
Member

smarter commented Feb 1, 2017

This also indirectly solves #1730, I think it's fine to require the user to be explicit when dealing with Array[Nothing]/Array[Null], though the error message as is might be confusing so we should not forget to add a detailed -explained message for it at some point.

@odersky
Copy link
Contributor Author

odersky commented Feb 1, 2017

@smarter It would solve #1730, but only if we also disallow forming a ClassTag[Nothing] or ClassTag[Null] manually. I think it would be a good idea to do this, though.

@smarter
Copy link
Member

smarter commented Feb 1, 2017

Yes, you're right, otherwise the soudness hole is still there.

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