Skip to content

Types refined with terms cannot be refined further #214

Closed
@smarter

Description

@smarter

The following code:

object Test {
  type F = { val x: Int }
  type G = F {}
}

makes dotty throw an exception because normalizeToRef does not handle parents which are RefinedType where the refinement is a term and not a type:

[error] Exception in thread "main" dotty.tools.dotc.core.Types$TypeError: unexpected parent type: RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,lang)),Object), x, TypeRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),scala),Int))
[error]         at dotty.tools.dotc.core.TypeOps$class.normalizeToRef$1(TypeOps.scala:286)
[error]         at dotty.tools.dotc.core.TypeOps$$anonfun$5.apply(TypeOps.scala:288)
[error]         at dotty.tools.dotc.core.TypeOps$$anonfun$5.apply(TypeOps.scala:288)
[error]         at scala.collection.immutable.List.map(List.scala:274)
[error]         at dotty.tools.dotc.core.TypeOps$class.normalizeToClassRefs(TypeOps.scala:288)
[error]         at dotty.tools.dotc.core.Contexts$Context.normalizeToClassRefs(Contexts.scala:51)
[error]         at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:489)
[error]         at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:424)
[error]         at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:151)
[error]         at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:133)
[error]         at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:234)
[error]         at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:920)
[error]         at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:945)
[error]         at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1005)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1017)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1015)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:162)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:146)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1015)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typedRefinedTypeTree$1.apply(Typer.scala:732)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typedRefinedTypeTree$1.apply(Typer.scala:728)
[error]         at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
[error]         at dotty.tools.dotc.typer.Typer.typedRefinedTypeTree(Typer.scala:728)
[error]         at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:991)
[error]         at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1007)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1017)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1015)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:162)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:146)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1015)
[error]         at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:503)
[error]         at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:510)
[error]         at dotty.tools.dotc.typer.Namer.typeDefSig(Namer.scala:670)
[error]         at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:402)
[error]         at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:428)
[error]         at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:424)
[error]         at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:151)
[error]         at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:133)
[error]         at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:234)
[error]         at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:920)
[error]         at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:945)
[error]         at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1005)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1017)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1015)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:162)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:146)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1015)
[error]         at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1039)
[error]         at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1051)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:852)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:834)
[error]         at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
[error]         at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:834)
[error]         at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:959)
[error]         at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1005)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1017)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1015)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:162)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:146)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1015)
[error]         at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1039)
[error]         at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1051)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:899)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:890)
[error]         at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
[error]         at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:890)
[error]         at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:996)
[error]         at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1007)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1017)
[error]         at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1015)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:162)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:146)
[error]         at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
[error]         at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1015)
[error]         at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1055)
[error]         at dotty.tools.dotc.typer.FrontEnd$$anonfun$typeCheck$1.apply$mcV$sp(FrontEnd.scala:37)
[error]         at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:16)
[error]         at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:35)
[error]         at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:48)
[error]         at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:48)
[error]         at scala.collection.immutable.List.foreach(List.scala:383)
[error]         at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:48)
[error]         at dotty.tools.dotc.Run$$anonfun$compileSources$1$$anonfun$apply$mcV$sp$3.apply(Run.scala:49)
[error]         at dotty.tools.dotc.Run$$anonfun$compileSources$1$$anonfun$apply$mcV$sp$3.apply(Run.scala:47)
[error]         at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
[error]         at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
[error]         at dotty.tools.dotc.Run$$anonfun$compileSources$1.apply$mcV$sp(Run.scala:47)
[error]         at dotty.tools.dotc.Run$$anonfun$compileSources$1.apply(Run.scala:39)
[error]         at dotty.tools.dotc.Run$$anonfun$compileSources$1.apply(Run.scala:39)
[error]         at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:68)
[error]         at dotty.tools.dotc.Run.compileSources(Run.scala:38)
[error]         at dotty.tools.dotc.Run.compile(Run.scala:29)
[error]         at dotty.tools.dotc.Driver.doCompile(Driver.scala:19)
[error]         at dotty.tools.dotc.Main$.doCompile(Main.scala:26)
[error]         at dotty.tools.dotc.Driver.process(Driver.scala:30)
[error]         at dotty.tools.dotc.Driver.main(Driver.scala:44)
[error]         at dotty.tools.dotc.Main.main(Main.scala)

Scalac compiles the code correctly, is this a missing feature in Dotty or are you not supporting these refinements intentionally?
CC @odersky @DarkDimius @namin

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions