Skip to content
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

implicit class with eponymous type parameter does not compile #7033

Closed
scabug opened this issue Jan 28, 2013 · 3 comments
Closed

implicit class with eponymous type parameter does not compile #7033

scabug opened this issue Jan 28, 2013 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jan 28, 2013

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
Copy link
Author

@scabug scabug commented Jan 28, 2013

@scabug
Copy link
Author

@scabug scabug commented Jan 28, 2013

@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
Copy link
Author

@scabug scabug commented Jan 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants