Skip to content

Commit 7596819

Browse files
committed
Check targetName when subtyping Refined Types
1 parent 55c2002 commit 7596819

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20842084
ExprType(info1.resType)
20852085
case info1 => info1
20862086

2087-
isSubInfo(info1, info2, m.symbol.info.orElse(info1))
2087+
(isSubInfo(info1, info2, m.symbol.info.orElse(info1)) && m.symbol.hasTargetName(m.symbol.name))
20882088
|| matchAbstractTypeMember(m.info)
20892089
|| (tp1.isStable && m.symbol.isStableMember && isSubType(TermRef(tp1, m.symbol), tp2.refinedInfo))
20902090
end qualifies

tests/neg/i18922.check

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i18922.scala:11:27 ------------------------------------------------------------
2+
11 |def test = doClose(Resource()) // error
3+
| ^^^^^^^^^^
4+
| Found: Resource
5+
| Required: Object{def close(): Unit}
6+
|
7+
| longer explanation available when compiling with `-explain`

tests/neg/i18922.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.annotation.targetName
2+
3+
def doClose(closable: { def close(): Unit }): Unit =
4+
import reflect.Selectable.reflectiveSelectable
5+
closable.close()
6+
7+
class Resource:
8+
@targetName("foo")
9+
def close(): Unit = ???
10+
11+
def test = doClose(Resource()) // error

0 commit comments

Comments
 (0)