Skip to content

Commit 3ffea6a

Browse files
committed
Fix quote re-typing error
This fixes at least the symptoms of #23423, see the discussion in the issue.
1 parent d944b61 commit 3ffea6a

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ object TypeOps:
125125
}
126126

127127
def isLegalPrefix(pre: Type)(using Context): Boolean =
128+
// This used to be `pre.isStable || !ctx.phase.isTyper` but the latter
129+
// condition was dropped in #21954 to make implicit search during the
130+
// inlining phase behave more like implicit search during the typer phase.
131+
// However, this change has lead to retyping issues (#23423) and I suspect
132+
// other issues could crop up as we might end up calling asSeenFrom with a
133+
// widened prefix in various situations post-typer.
128134
pre.isStable
129135

130136
/** Implementation of Types#simplified */

compiler/src/dotty/tools/dotc/staging/HealType.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ class HealType(pos: SrcPos)(using Context) extends TypeMap {
3232
*/
3333
def apply(tp: Type): Type =
3434
tp match
35-
case NonSpliceAlias(aliased) => this.apply(aliased)
35+
case NonSpliceAlias(aliased) =>
36+
val aliased1 = aliased
37+
if aliased1 ne aliased then aliased1
38+
else tp
3639
case tp: TypeRef => healTypeRef(tp)
3740
case tp: TermRef =>
3841
val inconsistentRoot = levelInconsistentRootOfPath(tp)

tests/pos-macros/i23423/A_1.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package pkg
2+
3+
import scala.quoted.*
4+
5+
trait HasElem {
6+
type Elem
7+
type Alias = Elem
8+
}
9+
10+
object Macro:
11+
inline def foo: Unit = ${fooImpl}
12+
def fooImpl(using Quotes): Expr[Unit] =
13+
'{
14+
val lll: (he: HasElem) => he.Alias =
15+
(hx: HasElem) => ???
16+
}

tests/pos-macros/i23423/B_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test:
2+
def test: Unit = pkg.Macro.foo
3+
// used to be error:
4+
// Found: (hx: pkg.HasElem) => hx.Elem
5+
// Required: (he: pkg.HasElem) => he.Elem
6+

0 commit comments

Comments
 (0)