Skip to content

Commit 9904e43

Browse files
committed
WIP
Fixes scala#13215
1 parent 2b74f88 commit 9904e43

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Symbols._, StdNames._, Annotations._, Trees._, Symbols._
1212
import Decorators._, DenotTransformers._
1313
import collection.{immutable, mutable}
1414
import util.{Property, SourceFile, NoSource}
15-
import NameKinds.{TempResultName, OuterSelectName}
15+
import NameKinds.{TempResultName, OuterSelectName, ModuleClassName}
1616
import typer.ConstFold
1717

1818
import scala.annotation.tailrec
@@ -358,6 +358,17 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
358358
Block(cdef :: Nil, New(cls.typeRef, Nil))
359359
}
360360

361+
def topLevelModule(name: TermName, ddefs: List[Tree])(using Context): List[Tree] = {
362+
val owner = ctx.owner// ddefs.head.symbol.owner
363+
val moduleSym = newCompleteModuleSymbol(owner, name,
364+
EmptyFlags, EmptyFlags, Nil, Scopes.newScopeWith(ddefs.map(_.symbol)*)).entered
365+
val moduleClass = newNormalizedClassSymbol(owner, ModuleClassName(name).toTypeName, Synthetic | Final | Module, List(defn.ObjectType), selfInfo = moduleSym.termRef).entered
366+
val constr = newConstructor(moduleClass, Synthetic, Nil, Nil).entered
367+
val vdef = ValDef(moduleSym, ref(defn.Predef_undefined)) //Apply(New(moduleClass.typeRef).select(constr), Nil))
368+
val cdef = ClassDef(moduleClass, DefDef(constr), ddefs.map(_.changeOwner(owner, moduleClass)))
369+
List(vdef, cdef)
370+
}
371+
361372
def Import(expr: Tree, selectors: List[untpd.ImportSelector])(using Context): Import =
362373
ta.assignType(untpd.Import(expr, selectors), newImportSymbol(ctx.owner, expr))
363374

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ object Symbols {
596596
def complete(denot: SymDenotation)(using Context): Unit = {
597597
val cls = denot.asClass.classSymbol
598598
val decls = newScope
599-
denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls)
599+
denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls, selfInfo)
600600
}
601601
}
602602
newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile)

compiler/src/dotty/tools/dotc/transform/AccessProxies.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ abstract class AccessProxies {
133133
val accessed = reference.symbol.asTerm
134134
var accessorClass = hostForAccessorOf(accessed: Symbol)
135135
if (accessorClass.exists) {
136-
if accessorClass.is(Package) then
137-
accessorClass = ctx.owner.topLevelClass
136+
// if accessorClass.is(Package) then
137+
// accessorClass = ctx.owner.topLevelClass
138138
val accessorName = accessorNameOf(accessed.name, accessorClass)
139139
val accessorInfo =
140140
accessed.info.ensureMethodic.asSeenFrom(accessorClass.thisType, accessed.owner)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2531,8 +2531,14 @@ class Typer extends Namer
25312531
inContext(ctx.packageContext(tree, pkg)) {
25322532
var stats1 = typedStats(tree.stats, pkg.moduleClass)._1
25332533
if (!ctx.isAfterTyper)
2534-
stats1 = stats1 ++ typedBlockStats(MainProxies.mainProxies(stats1))._1
2534+
stats1 = stats1 ::: typedBlockStats(MainProxies.mainProxies(stats1))._1
2535+
val topLevelInlineAccessors = addAccessorDefs(pkg, Nil)
2536+
if topLevelInlineAccessors.nonEmpty then
2537+
val moduleStats = tpd.topLevelModule("Inline$Accessors".toTermName, topLevelInlineAccessors)
2538+
stats1 = stats1 ::: moduleStats
2539+
25352540
cpy.PackageDef(tree)(pid1, stats1).withType(pkg.termRef)
2541+
// cpy.Template(tree)(body = Accessors.addAccessorDefs(tree.symbol.owner, tree.body))
25362542
}
25372543
case _ =>
25382544
// Package will not exist if a duplicate type has already been entered, see `tests/neg/1708.scala`

tests/pos/i13215.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package foo {
2+
trait Bar:
3+
inline def baz = Baz
4+
5+
private[foo] object Baz
6+
}

0 commit comments

Comments
 (0)