Skip to content

Commit cba210d

Browse files
committed
Fix problem when handling structural types without a nominal parent type.
We need to use Object as parent then, but this was forgotten.
1 parent b9e576a commit cba210d

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,12 @@ object desugar {
715715
* ==>
716716
* trait <refinement> extends parent { refinements }
717717
*
718+
* If the parent is missing, Object is assumed.
718719
* The result is used for validity checking, is thrown away afterwards.
719720
*/
720721
def refinedTypeToClass(tree: RefinedTypeTree)(implicit ctx: Context): TypeDef = {
721-
val impl = Template(emptyConstructor, tree.tpt :: Nil, EmptyValDef, tree.refinements)
722+
val parent = if (tree.tpt.isEmpty) TypeTree(defn.ObjectType) else tree.tpt
723+
val impl = Template(emptyConstructor, parent :: Nil, EmptyValDef, tree.refinements)
722724
TypeDef(Modifiers(Trait), tpnme.REFINE_CLASS, impl)
723725
}
724726

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ class Typer extends Namer with Applications with Implicits {
798798
}
799799

800800
def typedRefinedTypeTree(tree: untpd.RefinedTypeTree)(implicit ctx: Context): RefinedTypeTree = track("typedRefinedTypeTree") {
801-
val tpt1 = typedAheadType(tree.tpt)
801+
val tpt1 = if (tree.tpt.isEmpty) TypeTree(defn.ObjectType) else typedAheadType(tree.tpt)
802802
val refineClsDef = desugar.refinedTypeToClass(tree)
803803
val refineCls = createSymbol(refineClsDef).asClass
804804
val TypeDef(_, _, Template(_, _, _, refinements1)) = typed(refineClsDef)

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class tests extends CompilerTest {
3939
@Test def pos_packageobject() = compileFile(posDir, "packageobject")
4040
@Test def pos_overloaded() = compileFile(posDir, "overloaded")
4141
@Test def pos_templateParents() = compileFile(posDir, "templateParents")
42+
@Test def pos_structural() = compileFile(posDir, "structural")
4243

4344
@Test def neg_blockescapes() = compileFile(negDir, "blockescapesNeg", xerrors = 1)
4445
@Test def neg_typedapply() = compileFile(negDir, "typedapply", xerrors = 4)

0 commit comments

Comments
 (0)