Skip to content

Commit

Permalink
Check targetName when subtyping Refined Types
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Nov 25, 2023
1 parent 55c2002 commit 7596819
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
ExprType(info1.resType)
case info1 => info1

isSubInfo(info1, info2, m.symbol.info.orElse(info1))
(isSubInfo(info1, info2, m.symbol.info.orElse(info1)) && m.symbol.hasTargetName(m.symbol.name))
|| matchAbstractTypeMember(m.info)
|| (tp1.isStable && m.symbol.isStableMember && isSubType(TermRef(tp1, m.symbol), tp2.refinedInfo))
end qualifies
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i18922.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg/i18922.scala:11:27 ------------------------------------------------------------
11 |def test = doClose(Resource()) // error
| ^^^^^^^^^^
| Found: Resource
| Required: Object{def close(): Unit}
|
| longer explanation available when compiling with `-explain`
11 changes: 11 additions & 0 deletions tests/neg/i18922.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.annotation.targetName

def doClose(closable: { def close(): Unit }): Unit =
import reflect.Selectable.reflectiveSelectable
closable.close()

class Resource:
@targetName("foo")
def close(): Unit = ???

def test = doClose(Resource()) // error

0 comments on commit 7596819

Please sign in to comment.