Skip to content

Overloading method with implicit methods. #2002

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

Closed
nicolasstucki opened this issue Feb 20, 2017 · 1 comment
Closed

Overloading method with implicit methods. #2002

nicolasstucki opened this issue Feb 20, 2017 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

This is not overloading issue, but I have no better word for it. If one defines two methods with the same arguments but one with implicit and the other one without, the compiler will crash.

class A {
  def foo(i: Int): Int = i
  def foo(implicit i: Int): Int = i
}
java.lang.AssertionError: assertion failed: data race? overwriting symbol of type ((i: Int)Int)(A.this.foo),
long form = TermRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),A)),foo)/withSig(Signature(List(scala.Int),scala.Int)) of class class dotty.tools.dotc.core.Types$TermRefWithSignature,
last sym id = 3803, new sym id = 3804,
last owner = class A, new owner = class A,
period = frontend at run 2
	at scala.Predef$.assert(Predef.scala:165)
	at dotty.tools.dotc.core.Types$NamedType.checkSymAssign(Types.scala:1506)
	at dotty.tools.dotc.core.Types$NamedType.setDenot(Types.scala:1541)
	at dotty.tools.dotc.core.Types$NamedType.withDenot(Types.scala:1534)
	at dotty.tools.dotc.core.Types$TermRef$.withSigAndDenot(Types.scala:1942)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.termRefWithSig(SymDenotations.scala:1105)
	at dotty.tools.dotc.typer.TypeAssigner$$anonfun$assignType$5.apply(TypeAssigner.scala:498)
	at dotty.tools.dotc.typer.TypeAssigner$$anonfun$assignType$5.apply(TypeAssigner.scala:498)
	at dotty.tools.dotc.core.Types$Type.orElse(Types.scala:99)
	at dotty.tools.dotc.typer.TypeAssigner$class.assignType(TypeAssigner.scala:498)
	at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:64)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedDefDef$1.apply(Typer.scala:1243)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedDefDef$1.apply(Typer.scala:1214)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1214)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1505)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1562)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1581)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1579)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:136)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1579)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1603)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1623)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1315)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1261)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1261)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1508)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1562)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1581)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1579)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:136)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1579)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1603)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1623)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1423)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1410)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1410)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1547)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1563)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1581)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1579)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:136)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1579)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1635)
	at dotty.tools.dotc.typer.FrontEnd$$anonfun$typeCheck$1.apply$mcV$sp(FrontEnd.scala:64)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:62)
	at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:93)
	at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:93)
	at scala.collection.immutable.List.foreach(List.scala:381)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
@odersky
Copy link
Contributor

odersky commented Feb 21, 2017

That crash is only produced by -Yno-double-bindings, and it is inevitable. Without the option we get:

-- Error: i2002.scala ----------------------------------------------------------
3 |  def foo(implicit i: Int): Int = i
  |      ^
  |      method foo is already defined as method foo: (i: Int)Int
  |       (the definitions have matching type signatures)

@odersky odersky closed this as completed Feb 21, 2017
odersky added a commit to dotty-staging/dotty that referenced this issue Feb 21, 2017
… with <:<

Implicit and non-implicit functions are incomparable with <:<, but are
treated as equivalent with `matches`. This means implicit and non-implicit
functions of the same types override each other, but RefChecks will
give an error because their types are not subtypes.

Also contains a test for scala#2002.
odersky referenced this issue Feb 22, 2017
Fix #2000: Make implicit and non-implicit functions incomparable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants