scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

implicit class with eponymous type parameter does not compile #7033

Closed scabug closed 11 years ago

scabug commented 11 years ago
scala> class X[X](val a: Any)
defined class X

scala> implicit class X[X](val a: Any)
<console>:10: error: X does not take type parameters
       implicit class X[X](val a: Any)
                      ^
scabug commented 11 years ago

Imported From: https://issues.scala-lang.org/browse/SI-7033?orig=1 Reporter: @retronym

scabug commented 11 years ago

@retronym said (edited on Jan 28, 2013 12:51:11 PM UTC): Attempting to be more symful:

scala> ticket/7033 ~/code/scala2 git diff
diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
index acc4f7f..b314d1c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
@@ -389,7 +389,7 @@ trait MethodSynthesis {
         result
       }
       def derivedTree: DefDef          =
-        factoryMeth(mods & flagsMask | flagsExtra, name, tree, symbolic = false)
+        factoryMeth(mods & flagsMask | flagsExtra, name, tree, symbolic = true)
       def flagsExtra: Long             = METHOD | IMPLICIT | SYNTHETIC
       def flagsMask: Long              = AccessFlags
       def name: TermName               = tree.name.toTermName

scala> implicit class X(val x: Any)

scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving module $iw
    at scala.reflect.internal.Symbols$Symbol$$anonfun$info$3.apply(Symbols.scala:1210)
    at scala.reflect.internal.Symbols$Symbol$$anonfun$info$3.apply(Symbols.scala:1208)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.reflect.internal.Symbols$Symbol.lock(Symbols.scala:478)
    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1208)
    at scala.reflect.internal.Symbols$Symbol.tpe(Symbols.scala:1192)
    at scala.reflect.internal.Symbols$Symbol.tpeHK(Symbols.scala:1193)
    at scala.reflect.internal.Types$Type.computeMemberType(Types.scala:782)
    at scala.reflect.internal.Types$Type.memberType(Types.scala:779)
    at scala.reflect.internal.Types$class.defineUnderlyingOfSingleType(Types.scala:1524)
    at scala.reflect.internal.SymbolTable.defineUnderlyingOfSingleType(SymbolTable.scala:13)
    at scala.reflect.internal.Types$SingleType.underlying(Types.scala:1476)
    at scala.reflect.internal.Types$SingletonType.widen(Types.scala:1330)
    at scala.reflect.internal.Types$SingletonType.widen(Types.scala:1330)
    at scala.reflect.internal.Types$AsSeenFromMap.toPrefix$1(Types.scala:4518)
    at scala.reflect.internal.Types$AsSeenFromMap.apply(Types.scala:4533)
    at scala.reflect.internal.Types$TypeMap.mapOver(Types.scala:4160)
    at scala.reflect.internal.Types$AsSeenFromMap.apply(Types.scala:4615)
    at scala.reflect.internal.Types$Type.asSeenFrom(Types.scala:752)
    at scala.reflect.internal.Types$Type.computeMemberType(Types.scala:786)
    at scala.reflect.internal.Types$Type.memberType(Types.scala:779)
    at scala.reflect.internal.TreeGen.mkAttributedSelect(TreeGen.scala:184)
    at scala.reflect.internal.TreeGen.mkAttributedRef(TreeGen.scala:124)
    at scala.reflect.internal.TreeGen.mkAttributedRef(TreeGen.scala:130)
    at scala.tools.nsc.ast.TreeDSL$CODE$.REF(TreeDSL.scala:307)
    at scala.tools.nsc.typechecker.Unapplies$class.classType(Unapplies.scala:83)
    at scala.tools.nsc.typechecker.Unapplies$class.classtpe$1(Unapplies.scala:139)
    at scala.tools.nsc.typechecker.Unapplies$class.factoryMeth(Unapplies.scala:141)
    at scala.tools.nsc.interpreter.ReplGlobal$$anon$1.factoryMeth(ReplGlobal.scala:24)
    at scala.tools.nsc.typechecker.MethodSynthesis$MethodSynth$ImplicitClassWrapper.derivedTree(MethodSynthesis.scala:392)

<console>:7: error: illegal cyclic reference involving object $iw
       implicit class X(val x: Any)
                      ^
<console>:12: error: illegal inheritance;
 self-type type does not conform to scala.AnyRef's selftype AnyRef
}
^
scabug commented 11 years ago

@retronym said: https://github.com/scala/scala/pull/1992