Skip to content

Commit 4b36c71

Browse files
committed
Don't add parent refinements if they are typed as skolems
1 parent f7e5df5 commit 4b36c71

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ContextOps.enter
88
import TypeApplications.EtaExpansion
99
import collection.mutable
1010
import config.Printers.typr
11+
import ast.untpd
1112

1213
/** Operations that are shared between Namer and TreeUnpickler */
1314
object NamerOps:
@@ -38,19 +39,22 @@ object NamerOps:
3839
* unless it is null.
3940
*/
4041
extension (tp: Type)
41-
def separateRefinements(cls: ClassSymbol, refinements: mutable.LinkedHashMap[Name, Type] | Null)(using Context): Type =
42+
def separateRefinements(cls: ClassSymbol, refinements: mutable.LinkedHashMap[Name, Type] | Null, parent: untpd.Tree)(using Context): Type =
4243
tp match
4344
case RefinedType(tp1, rname, rinfo) =>
44-
try tp1.separateRefinements(cls, refinements)
45+
try tp1.separateRefinements(cls, refinements, parent)
4546
finally
4647
if refinements != null then
47-
refinements(rname) = refinements.get(rname) match
48-
case Some(tp) => tp & rinfo
49-
case None => rinfo
48+
if rinfo.existsPart(_.isInstanceOf[SkolemType]) then
49+
report.warning(em"Couldn't determine the precise type of refinement $rname in $tp", parent.srcPos)
50+
else
51+
refinements(rname) = refinements.get(rname) match
52+
case Some(tp) => tp & rinfo
53+
case None => rinfo
5054
case tp @ AnnotatedType(tp1, ann) =>
51-
tp.derivedAnnotatedType(tp1.separateRefinements(cls, refinements), ann)
55+
tp.derivedAnnotatedType(tp1.separateRefinements(cls, refinements, parent), ann)
5256
case tp: RecType =>
53-
tp.parent.substRecThis(tp, cls.thisType).separateRefinements(cls, refinements)
57+
tp.parent.substRecThis(tp, cls.thisType).separateRefinements(cls, refinements, parent)
5458
case tp =>
5559
tp
5660

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ class TreeUnpickler(reader: TastyReader,
10801080
}
10811081
val parentReader = fork
10821082
val parents = readParents(withArgs = false)(using parentCtx)
1083-
val parentTypes = parents.map(_.tpe.dealiasKeepAnnots.separateRefinements(cls, null))
1083+
val parentTypes = parents.map(p => p.tpe.dealiasKeepAnnots.separateRefinements(cls, null, p))
10841084
if cls.is(JavaDefined) && parentTypes.exists(_.derivesFrom(defn.JavaAnnotationClass)) then
10851085
cls.setFlag(JavaAnnotation)
10861086
val self =

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ private class ExtractAPICollector(nonLocalClassSymbols: mutable.HashSet[Symbol])
654654
case SuperType(thistpe, supertpe) =>
655655
val s = combineApiTypes(apiType(thistpe), apiType(supertpe))
656656
withMarker(s, superMarker)
657+
case SkolemType(info) =>
658+
// for skolem types, fallback to the underlying type
659+
apiType(info)
657660
case _ => {
658661
internalError(i"Unhandled type $tp of class ${tp.getClass}")
659662
Constants.emptyType

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ class Namer { typer: Typer =>
16151615
else {
16161616
val pt = checkClassType(
16171617
if Feature.enabled(modularity)
1618-
then ptype.separateRefinements(cls, parentRefinements)
1618+
then ptype.separateRefinements(cls, parentRefinements, parent)
16191619
else ptype,
16201620
parent.srcPos,
16211621
traitReq = parent ne parents.head,

tests/warn/i22456.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Warning: tests/warn/i22456.scala:5:10 -------------------------------------------------------------------------------
2+
5 | extends T(x + 1) // warn
3+
| ^^^^^^^^
4+
| Couldn't determine the precise type of refinement y in T{val y: (?1 : Int)}
5+
|
6+
| where: ?1 is an unknown value of type Int

tests/warn/i22456.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import language.experimental.modularity
2+
3+
class T(tracked val y: Int)
4+
class C(tracked val x: Int)
5+
extends T(x + 1) // warn

0 commit comments

Comments
 (0)