Skip to content
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

Check @targetName when subtyping Refined Types #19081

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2084,9 +2084,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
ExprType(info1.resType)
case info1 => info1

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

tp1.member(name).hasAltWithInline(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
7 changes: 7 additions & 0 deletions tests/neg/targetName-refine.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg/targetName-refine.scala:7:27 --------------------------------------------------
7 |val x: T { def f: Int } = C() // error
| ^^^
| Found: C
| Required: T{def f: Int}
|
| longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ trait T:
class C extends T:
@targetName("f2") def f: Int = 1

val x: T { def f: Int } = C()
val x: T { def f: Int } = C() // error

Loading