Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d27cf2d

Browse files
authored
Fix regressions in asSeenFrom introduced in 3.7 (#23438)
The body of isLegalPrefix used to read: pre.isStable || !ctx.phase.isTyper but was changed to drop the second condition in #21954 (originally included in 3.6.4-RC1, reverted from 3.6.4 final but back in 3.7). This has led to a number of regressions, the last ones discussed in #23423. To make the testcases added in #21594 pass, this PR proposes a less drastic change: relax isLegalPrefix as before, unless we're doing an implicit search. This should dramatically reduce the possibility for regressions. Fixes #23423. Fixes #22676.
2 parents 8dd0770 + 2e4bc0a commit d27cf2d

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ object TypeOps:
125125
}
126126

127127
def isLegalPrefix(pre: Type)(using Context): Boolean =
128-
pre.isStable
128+
// isLegalPrefix is relaxed after typer unless we're doing an implicit
129+
// search (this matters when doing summonInline in an inline def like in tests/pos/i17222.8.scala).
130+
pre.isStable || !ctx.phase.isTyper && ctx.mode.is(Mode.ImplicitsEnabled)
129131

130132
/** Implementation of Types#simplified */
131133
def simplify(tp: Type, theMap: SimplifyMap | Null)(using Context): Type = {

‎tests/neg-custom-args/captures/lazylist.check‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylist.scala:41:42 -------------------------------------
3030
41 | val ref4c: LazyList[Int]^{cap1, ref3} = ref4 // error
3131
| ^^^^
32-
| Found: (ref4 : lazylists.LazyList[Int]^{cap3, ref1, ref2})
32+
| Found: (ref4 : lazylists.LazyList[Int]^{cap3, cap1, cap2})
3333
| Required: lazylists.LazyList[Int]^{cap1, ref3}
3434
|
3535
| longer explanation available when compiling with `-explain`

‎tests/neg/6314-6.check‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
|object creation impossible, since def apply(fa: String): Int in trait XX in object Test3 is not defined
55
|(Note that
66
| parameter String in def apply(fa: String): Int in trait XX in object Test3 does not match
7-
| parameter Test3.Bar[X & (X & Y)] in def apply(fa: Test3.Bar[X & YY.this.Foo]): Test3.Bar[Y & YY.this.Foo] in trait YY in object Test3
7+
| parameter Test3.Bar[X & Object with Test3.YY {...}#Foo] in def apply(fa: Test3.Bar[X & YY.this.Foo]): Test3.Bar[Y & YY.this.Foo] in trait YY in object Test3
88
| )
99
-- Error: tests/neg/6314-6.scala:52:3 ----------------------------------------------------------------------------------
1010
52 | (new YY {}).boom // error: object creation impossible
1111
| ^
1212
|object creation impossible, since def apply(fa: String): Int in trait XX in object Test4 is not defined
1313
|(Note that
1414
| parameter String in def apply(fa: String): Int in trait XX in object Test4 does not match
15-
| parameter Test4.Bar[X & (X & Y)] in def apply(fa: Test4.Bar[X & YY.this.FooAlias]): Test4.Bar[Y & YY.this.FooAlias] in trait YY in object Test4
15+
| parameter Test4.Bar[X & Object with Test4.YY {...}#FooAlias] in def apply(fa: Test4.Bar[X & YY.this.FooAlias]): Test4.Bar[Y & YY.this.FooAlias] in trait YY in object Test4
1616
| )

‎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+

‎tests/pos/i22676.scala‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package example
2+
3+
trait Example {
4+
class Input
5+
6+
type Output[A] = A match {
7+
case Input => Int
8+
}
9+
}
10+
11+
class Ref(ref: Example#Input)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /