-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4007 from Jasper-M/topic/implicit-ambiguous
Fix #3797: Add support for @implicitAmbiguous
- Loading branch information
Showing
5 changed files
with
214 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
compiler/test/dotty/tools/dotc/reporting/UserDefinedErrorMessages.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package dotty.tools | ||
package dotc | ||
package reporting | ||
|
||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.reporting.diagnostic.messages._ | ||
import org.junit.Assert._ | ||
import org.junit.Test | ||
|
||
class UserDefinedErrorMessages extends ErrorMessagesTest { | ||
@Test def userDefinedImplicitAmbiguous1 = | ||
checkMessagesAfter("frontend") { | ||
""" | ||
|object Test { | ||
| trait =!=[C, D] | ||
| | ||
| implicit def neq[E, F] : E =!= F = null | ||
| | ||
| @annotation.implicitAmbiguous("Could not prove ${J} =!= ${J}") | ||
| implicit def neqAmbig1[G, H, J] : J =!= J = null | ||
| implicit def neqAmbig2[I] : I =!= I = null | ||
| | ||
| implicitly[Int =!= Int] | ||
|} | ||
""".stripMargin | ||
}.expect { (itcx, messages) => | ||
import diagnostic.NoExplanation | ||
implicit val ctx: Context = itcx | ||
|
||
assertMessageCount(1, messages) | ||
val (m: NoExplanation) :: Nil = messages | ||
|
||
assertEquals(m.msg, "Could not prove Int =!= Int") | ||
} | ||
|
||
@Test def userDefinedImplicitAmbiguous2 = | ||
checkMessagesAfter("frontend") { | ||
""" | ||
|object Test { | ||
| trait =!=[C, D] | ||
| | ||
| implicit def neq[E, F] : E =!= F = null | ||
| | ||
| implicit def neqAmbig1[G, H, J] : J =!= J = null | ||
| @annotation.implicitAmbiguous("Could not prove ${I} =!= ${I}") | ||
| implicit def neqAmbig2[I] : I =!= I = null | ||
| | ||
| implicitly[Int =!= Int] | ||
|} | ||
""".stripMargin | ||
}.expect { (itcx, messages) => | ||
import diagnostic.NoExplanation | ||
implicit val ctx: Context = itcx | ||
|
||
assertMessageCount(1, messages) | ||
val (m: NoExplanation) :: Nil = messages | ||
|
||
assertEquals(m.msg, "Could not prove Int =!= Int") | ||
} | ||
|
||
@Test def userDefinedImplicitAmbiguous3 = | ||
checkMessagesAfter("frontend") { | ||
""" | ||
|object Test { | ||
| trait =!=[C, D] | ||
| | ||
| implicit def neq[E, F] : E =!= F = null | ||
| | ||
| @annotation.implicitAmbiguous("Could not prove ${J} =!= ${J}") | ||
| implicit def neqAmbig1[G, H, J] : J =!= J = null | ||
| @annotation.implicitAmbiguous("Could not prove ${I} =!= ${I}") | ||
| implicit def neqAmbig2[I] : I =!= I = null | ||
| | ||
| implicitly[Int =!= Int] | ||
|} | ||
""".stripMargin | ||
}.expect { (itcx, messages) => | ||
import diagnostic.NoExplanation | ||
implicit val ctx: Context = itcx | ||
|
||
assertMessageCount(1, messages) | ||
val (m: NoExplanation) :: Nil = messages | ||
|
||
assertEquals(m.msg, "Could not prove Int =!= Int") | ||
} | ||
|
||
@Test def userDefinedImplicitAmbiguous4 = | ||
checkMessagesAfter("frontend") { | ||
""" | ||
|class C { | ||
| @annotation.implicitAmbiguous("msg A=${A}") | ||
| implicit def f[A](x: Int): String = "f was here" | ||
| implicit def g(x: Int): String = "f was here" | ||
| def test: Unit = { | ||
| implicitly[Int => String] | ||
| } | ||
|} | ||
""".stripMargin | ||
}.expect { (itcx, messages) => | ||
import diagnostic.NoExplanation | ||
implicit val ctx: Context = itcx | ||
|
||
assertMessageCount(1, messages) | ||
val (m: NoExplanation) :: Nil = messages | ||
|
||
assertEquals(m.msg, "msg A=Any") | ||
} | ||
|
||
@Test def userDefinedImplicitAmbiguous5 = | ||
checkMessagesAfter("frontend") { | ||
""" | ||
|class C { | ||
| @annotation.implicitAmbiguous("msg A=${A}") | ||
| implicit def f[A](implicit x: String): Int = 1 | ||
| implicit def g: Int = 2 | ||
| def test: Unit = { | ||
| implicit val s: String = "Hello" | ||
| implicitly[Int] | ||
| } | ||
|} | ||
""".stripMargin | ||
}.expect { (itcx, messages) => | ||
import diagnostic.NoExplanation | ||
implicit val ctx: Context = itcx | ||
|
||
assertMessageCount(1, messages) | ||
val (m: NoExplanation) :: Nil = messages | ||
|
||
assertEquals(m.msg, "msg A=Any") | ||
} | ||
} |