Skip to content

Commit 33e34b7

Browse files
Merge pull request #9373 from dotty-staging/fix-#9369
Fix #9369: Use new extension syntax
2 parents 8449fce + 88bb954 commit 33e34b7

File tree

8 files changed

+370
-356
lines changed

8 files changed

+370
-356
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -116,58 +116,62 @@ object DottyBackendInterface {
116116
ctx.requiredModule(className)
117117
}
118118

119-
extension symExtensions on (sym: Symbol) {
120-
121-
def isInterface(using Context): Boolean = (sym.is(PureInterface)) || sym.is(Trait)
122-
123-
def isStaticConstructor(using Context): Boolean = (sym.isStaticMember && sym.isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR)
124-
125-
def isStaticMember(using Context): Boolean = (sym ne NoSymbol) &&
126-
(sym.is(JavaStatic) || sym.isScalaStatic)
127-
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
128-
129-
/**
130-
* True for module classes of modules that are top-level or owned only by objects. Module classes
131-
* for such objects will get a MODULE$ flag and a corresponding static initializer.
132-
*/
133-
def isStaticModuleClass(using Context): Boolean =
134-
(sym.is(Module)) && {
135-
// scalac uses atPickling here
136-
// this would not work if modules are created after pickling
137-
// for example by specialization
138-
val original = toDenot(sym).initial
139-
val validity = original.validFor
140-
atPhase(validity.phaseId) {
141-
toDenot(sym).isStatic
119+
given symExtensions as AnyRef:
120+
extension (sym: Symbol):
121+
122+
def isInterface(using Context): Boolean = (sym.is(PureInterface)) || sym.is(Trait)
123+
124+
def isStaticConstructor(using Context): Boolean = (sym.isStaticMember && sym.isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR)
125+
126+
def isStaticMember(using Context): Boolean = (sym ne NoSymbol) &&
127+
(sym.is(JavaStatic) || sym.isScalaStatic)
128+
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
129+
130+
/**
131+
* True for module classes of modules that are top-level or owned only by objects. Module classes
132+
* for such objects will get a MODULE$ flag and a corresponding static initializer.
133+
*/
134+
def isStaticModuleClass(using Context): Boolean =
135+
(sym.is(Module)) && {
136+
// scalac uses atPickling here
137+
// this would not work if modules are created after pickling
138+
// for example by specialization
139+
val original = toDenot(sym).initial
140+
val validity = original.validFor
141+
atPhase(validity.phaseId) {
142+
toDenot(sym).isStatic
143+
}
142144
}
143-
}
144145

145146

146147

147-
def originalLexicallyEnclosingClass(using Context): Symbol =
148-
// used to populate the EnclosingMethod attribute.
149-
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
150-
if (sym.exists) {
151-
val validity = toDenot(sym).initial.validFor
152-
atPhase(validity.phaseId) {
153-
toDenot(sym).lexicallyEnclosingClass
148+
def originalLexicallyEnclosingClass(using Context): Symbol =
149+
// used to populate the EnclosingMethod attribute.
150+
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
151+
if (sym.exists) {
152+
val validity = toDenot(sym).initial.validFor
153+
atPhase(validity.phaseId) {
154+
toDenot(sym).lexicallyEnclosingClass
155+
}
156+
} else NoSymbol
157+
158+
/**
159+
* True for module classes of package level objects. The backend will generate a mirror class for
160+
* such objects.
161+
*/
162+
def isTopLevelModuleClass(using Context): Boolean =
163+
sym.is(ModuleClass) &&
164+
atPhase(flattenPhase) {
165+
toDenot(sym).owner.is(PackageClass)
154166
}
155-
} else NoSymbol
156-
157-
/**
158-
* True for module classes of package level objects. The backend will generate a mirror class for
159-
* such objects.
160-
*/
161-
def isTopLevelModuleClass(using Context): Boolean =
162-
sym.is(ModuleClass) &&
163-
atPhase(flattenPhase) {
164-
toDenot(sym).owner.is(PackageClass)
165-
}
166167

167-
def javaSimpleName(using Context): String = toDenot(sym).name.mangledString
168-
def javaClassName(using Context): String = toDenot(sym).fullName.mangledString
169-
def javaBinaryName(using Context): String = javaClassName.replace('.', '/')
170-
}
168+
def javaSimpleName(using Context): String = toDenot(sym).name.mangledString
169+
def javaClassName(using Context): String = toDenot(sym).fullName.mangledString
170+
def javaBinaryName(using Context): String = javaClassName.replace('.', '/')
171+
172+
end extension
173+
174+
end symExtensions
171175

172176
private val primitiveCompilationUnits = Set(
173177
"Unit.scala",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ object Comments {
1515
val ContextDoc: Key[ContextDocstrings] = new Key[ContextDocstrings]
1616

1717
/** Decorator for getting docbase out of context */
18-
extension CommentsContext on (c: Context):
19-
def docCtx: Option[ContextDocstrings] = c.property(ContextDoc)
18+
given CommentsContext as AnyRef:
19+
extension (c: Context) def docCtx: Option[ContextDocstrings] = c.property(ContextDoc)
2020

2121
/** Context for Docstrings, contains basic functionality for getting
2222
* docstrings via `Symbol` and expanding templates

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,17 @@ object Contexts {
603603
def setDebug: this.type = setSetting(base.settings.Ydebug, true)
604604
}
605605

606-
extension ops on (c: Context):
607-
def addNotNullInfo(info: NotNullInfo) =
608-
c.withNotNullInfos(c.notNullInfos.extendWith(info))
606+
given ops as AnyRef:
607+
extension (c: Context):
608+
def addNotNullInfo(info: NotNullInfo) =
609+
c.withNotNullInfos(c.notNullInfos.extendWith(info))
609610

610-
def addNotNullRefs(refs: Set[TermRef]) =
611-
c.addNotNullInfo(NotNullInfo(refs, Set()))
611+
def addNotNullRefs(refs: Set[TermRef]) =
612+
c.addNotNullInfo(NotNullInfo(refs, Set()))
612613

613-
def withNotNullInfos(infos: List[NotNullInfo]): Context =
614-
if c.notNullInfos eq infos then c else c.fresh.setNotNullInfos(infos)
614+
def withNotNullInfos(infos: List[NotNullInfo]): Context =
615+
if c.notNullInfos eq infos then c else c.fresh.setNotNullInfos(infos)
616+
end ops
615617

616618
// TODO: Fix issue when converting ModeChanges and FreshModeChanges to extension givens
617619
implicit class ModeChanges(val c: Context) extends AnyVal {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ object Decorators {
161161
def & (ys: List[T]): List[T] = xs filter (ys contains _)
162162
}
163163

164-
extension ListOfListDecorator on [T, U](xss: List[List[T]]):
165-
def nestedMap(f: T => U): List[List[U]] =
166-
xss.map(_.map(f))
167-
def nestedMapConserve(f: T => U): List[List[U]] =
168-
xss.mapconserve(_.mapconserve(f))
169-
def nestedZipWithConserve(yss: List[List[U]])(f: (T, U) => T): List[List[T]] =
170-
xss.zipWithConserve(yss)((xs, ys) => xs.zipWithConserve(ys)(f))
164+
given ListOfListDecorator as AnyRef:
165+
extension [T, U](xss: List[List[T]]):
166+
def nestedMap(f: T => U): List[List[U]] =
167+
xss.map(_.map(f))
168+
def nestedMapConserve(f: T => U): List[List[U]] =
169+
xss.mapconserve(_.mapconserve(f))
170+
def nestedZipWithConserve(yss: List[List[U]])(f: (T, U) => T): List[List[T]] =
171+
xss.zipWithConserve(yss)((xs, ys) => xs.zipWithConserve(ys)(f))
172+
end extension
171173

172174
implicit class TextToString(val text: Text) extends AnyVal {
173175
def show(using Context): String = text.mkString(ctx.settings.pageWidth.value, ctx.settings.printLines.value)

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object Cbufs {
3030
object Cbuf:
3131
def apply(): Cbuf = new StringBuilder(TargetCapacity)
3232

33-
extension StringBuilderOps on (buf: Cbuf):
33+
extension (buf: Cbuf):
3434
def clear(): Unit = {
3535
if buf.capacity() > TargetCapacity then
3636
buf.setLength(TargetCapacity)
@@ -48,6 +48,7 @@ object Cbufs {
4848
def isEmpty: Boolean = buf.length() == 0
4949
def length: Int = buf.length()
5050
def last: Char = buf.charAt(buf.length() - 1)
51+
end extension
5152
}
5253

5354
import Cbufs._

0 commit comments

Comments
 (0)