Skip to content

Fix #3630: Handle classtag searches with wildcard arguments #3718

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 1 commit into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ object TypeErasure {
case _ => false
}
case tp: TypeParamRef => false
case tp: TypeBounds => false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would hasStableErasure(tp.lo) && hasStableErasure(tp.hi) be incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because we fall into this case also via TypeProxy.

case tp: TypeProxy => hasStableErasure(tp.superType)
case tp: AndOrType => hasStableErasure(tp.tp1) && hasStableErasure(tp.tp2)
case _ => false
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ trait Implicits { self: Typer =>
* synthesize a class tag for `T`.
*/
def synthesizedClassTag(formal: Type)(implicit ctx: Context): Tree =
formal.argTypes match {
formal.argInfos match {
case arg :: Nil =>
fullyDefinedType(arg, "ClassTag argument", pos) match {
case defn.ArrayOf(elemTp) =>
Expand Down
1 change: 1 addition & 0 deletions tests/neg/i3630.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class U { Array(Array(2), Array("a")) } // error: no classtag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to disallow this? It seems to work OK in scalac.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full error message says:

No ClassTag available for Array[_ >: Int & String <: Int | String]

The inferred type of the outer array is

Array[Array[_ >: Int & String <: Int | String]]

That is indeed the best type. But there's no ClassTag. We could infer some wider type such as

Array[AnyRef](Array(2), Array("a"))

for the outer array. But it would be a special case. And I am not sure whether in the end it would not be better to reject this weird construction as an error and demand that the user write

Array[AnyRef](Array(2), Array("a"))

explicitly.