Skip to content

Commit cd02a22

Browse files
committed
Always package same-named objects and types together
1 parent e579bfa commit cd02a22

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,17 +1153,21 @@ object desugar {
11531153
* - all pattern, value and method definitions
11541154
* - non-class type definitions
11551155
* - implicit classes and objects
1156-
* - companion objects of opaque types
1156+
* - "companion objects" of wrapped type definitions
1157+
* (i.e. objects having the same name as a wrapped type)
11571158
*/
11581159
def packageDef(pdef: PackageDef)(implicit ctx: Context): PackageDef = {
1159-
val opaqueNames = pdef.stats.collect {
1160-
case stat: TypeDef if stat.mods.is(Opaque) => stat.name
1160+
def isWrappedType(stat: TypeDef): Boolean =
1161+
!stat.isClassDef || stat.mods.isOneOf(DelegateOrImplicit)
1162+
val wrappedTypeNames = pdef.stats.collect {
1163+
case stat: TypeDef if isWrappedType(stat) => stat.name
11611164
}
11621165
def needsObject(stat: Tree) = stat match {
11631166
case _: ValDef | _: PatDef | _: DefDef | _: Export => true
11641167
case stat: ModuleDef =>
1165-
stat.mods.isOneOf(DelegateOrImplicit) || opaqueNames.contains(stat.name.stripModuleClassSuffix.toTypeName)
1166-
case stat: TypeDef => !stat.isClassDef || stat.mods.isOneOf(DelegateOrImplicit)
1168+
stat.mods.isOneOf(DelegateOrImplicit) ||
1169+
wrappedTypeNames.contains(stat.name.stripModuleClassSuffix.toTypeName)
1170+
case stat: TypeDef => isWrappedType(stat)
11671171
case _ => false
11681172
}
11691173
val (nestedStats, topStats) = pdef.stats.partition(needsObject)

0 commit comments

Comments
 (0)