Skip to content

Should class be allowed to extend refinements? #248

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

Closed
smarter opened this issue Nov 26, 2014 · 1 comment
Closed

Should class be allowed to extend refinements? #248

smarter opened this issue Nov 26, 2014 · 1 comment

Comments

@smarter
Copy link
Member

smarter commented Nov 26, 2014

Refining with a type

class A { type T }
type X = A { type T = Int }
class B extends X

This works, is that what we want?

Refining with a term

class A
type X = A { def f: Int }
class B extends X

This throws an exception in normalizeToRef because the normalization to a TypeRef only handles refining with a type. Do we want to allow this?

Exception in thread "main" dotty.tools.dotc.core.Types$TypeError: unexpected parent type: RefinedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),O$)),A), f, ExprType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),scala),Int)))
        at dotty.tools.dotc.core.TypeOps$class.normalizeToRef$1(TypeOps.scala:296)
        at dotty.tools.dotc.core.TypeOps$$anonfun$5.apply(TypeOps.scala:298)
        at dotty.tools.dotc.core.TypeOps$$anonfun$5.apply(TypeOps.scala:298)
        at scala.collection.immutable.List.map(List.scala:274)
        at dotty.tools.dotc.core.TypeOps$class.normalizeToClassRefs(TypeOps.scala:298)
        at dotty.tools.dotc.core.Contexts$Context.normalizeToClassRefs(Contexts.scala:51)
        at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:493)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:427)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:151)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:133)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:234)
        at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:941)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:966)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1026)
        at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1038)
        at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1036)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:147)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1036)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1060)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1071)
        at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:873)
        at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:855)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:855)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:980)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1026)
        at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1038)
        at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1036)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:147)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1036)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1060)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1071)
        at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:920)
        at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:911)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:911)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1017)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1028)
        at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1038)
        at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1036)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:147)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:51)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1036)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1075)
        at dotty.tools.dotc.typer.FrontEnd$$anonfun$typeCheck$1.apply$mcV$sp(FrontEnd.scala:40)
        at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:17)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:38)
        at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:51)
        at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:51)
        at scala.collection.immutable.List.foreach(List.scala:383)
        at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:51)
        at dotty.tools.dotc.Run$$anonfun$compileSources$1$$anonfun$apply$mcV$sp$3.apply(Run.scala:49)
        at dotty.tools.dotc.Run$$anonfun$compileSources$1$$anonfun$apply$mcV$sp$3.apply(Run.scala:47)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
        at dotty.tools.dotc.Run$$anonfun$compileSources$1.apply$mcV$sp(Run.scala:47)
        at dotty.tools.dotc.Run$$anonfun$compileSources$1.apply(Run.scala:39)
        at dotty.tools.dotc.Run$$anonfun$compileSources$1.apply(Run.scala:39)
        at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:68)
        at dotty.tools.dotc.Run.compileSources(Run.scala:38)
        at dotty.tools.dotc.Run.compile(Run.scala:29)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:19)
        at dotty.tools.dotc.Main$.doCompile(Main.scala:26)
        at dotty.tools.dotc.Driver.process(Driver.scala:30)
        at dotty.tools.dotc.Driver.main(Driver.scala:44)
        at dotty.tools.dotc.Main.main(Main.scala)

CC @odersky

@odersky
Copy link
Contributor

odersky commented Dec 13, 2014

I believe we should not allow inheriting refined types in classes. Will add code that prevents it.

odersky added a commit that referenced this issue Dec 13, 2014
Fix #248: Class cannot inherit from refinement types
tgodzik added a commit to tgodzik/scala3 that referenced this issue Apr 29, 2025
Backport "Avoid infinite recursion when looking for suggestions" to 3.3 LTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants