Skip to content

Commit bb1ce48

Browse files
authored
Merge pull request scala#7373 from hrhino/t11228
Put @implicitAmbiguous annotation on the getter, not the field
2 parents 0f07cc1 + bd82f03 commit bb1ce48

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ trait PatternTypers {
102102
else if (isOkay)
103103
fun
104104
else if (isEmptyType == NoType)
105-
CaseClassConstructorError(fun, s"an unapply result must have a member `def isEmpty: Boolean")
105+
CaseClassConstructorError(fun, s"an unapply result must have a member `def isEmpty: Boolean`")
106106
else
107-
CaseClassConstructorError(fun, s"an unapply result must have a member `def isEmpty: Boolean (found: def isEmpty: $isEmptyType)")
107+
CaseClassConstructorError(fun, s"an unapply result must have a member `def isEmpty: Boolean` (found: `def isEmpty: $isEmptyType`)")
108108
}
109109

110110
def typedArgsForFormals(args: List[Tree], formals: List[Type], mode: Mode): List[Tree] = {

src/library/scala/annotation/implicitAmbiguous.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ package scala.annotation
4141
* @author Brian McKenna
4242
* @since 2.12.0
4343
*/
44+
@meta.getter
4445
final class implicitAmbiguous(msg: String) extends scala.annotation.StaticAnnotation
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
implicit-ambiguous-val.scala:16: error: unexpected string
2+
meh("")
3+
^
4+
one error found
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sealed trait NotString[T]
2+
3+
object NotString extends NotString0 {
4+
@annotation.implicitAmbiguous("unexpected string")
5+
implicit val stringAmb_1: NotString[String] = null
6+
implicit val stringAmb_2: NotString[String] = null
7+
}
8+
sealed abstract class NotString0 {
9+
implicit def notString[T]: NotString[T] = null
10+
}
11+
12+
object Test {
13+
def meh[T: NotString](t: T) = ()
14+
15+
meh(12)
16+
meh("")
17+
}

test/files/neg/t7850.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
t7850.scala:11: error: an unapply result must have a member `def isEmpty: Boolean (found: def isEmpty: Casey)
1+
t7850.scala:11: error: an unapply result must have a member `def isEmpty: Boolean` (found: `def isEmpty: Casey`)
22
val Casey(x1) = new Casey(1)
33
^
4-
t7850.scala:12: error: an unapply result must have a member `def isEmpty: Boolean
4+
t7850.scala:12: error: an unapply result must have a member `def isEmpty: Boolean`
55
val Dingy(x2) = new Dingy(1)
66
^
77
two errors found

0 commit comments

Comments
 (0)