Skip to content

Commit 299639e

Browse files
committed
Avoid extension as an identifier.
It's now a keyword, need to enclose in backticks when used as an identifier.
1 parent ce4cc6a commit 299639e

File tree

10 files changed

+20
-20
lines changed

10 files changed

+20
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class GenBCode extends Phase {
5757
if (myOutput eq null) {
5858
val path = Directory(ctx.settings.outputDir.value)
5959
myOutput =
60-
if (path.extension == "jar") JarArchive.create(path)
60+
if (path.`extension` == "jar") JarArchive.create(path)
6161
else new PlainDirectory(path)
6262
}
6363
myOutput

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ object desugar {
785785
*
786786
* <body2> = <body1> where each method definition gets <combined-params> as last parameter section.
787787
*/
788-
def extension(tree: Extension)(implicit ctx: Context): Tree = {
788+
def extensionDef(tree: Extension)(implicit ctx: Context): Tree = {
789789
val Extension(name, extended, impl) = tree
790790
val isSimpleExtension = impl.parents.isEmpty
791791

@@ -832,7 +832,7 @@ object desugar {
832832
else defDef(tree)
833833
case tree: ModuleDef => moduleDef(tree)
834834
case tree: PatDef => patDef(tree)
835-
case tree: Extension => extension(tree)
835+
case tree: Extension => extensionDef(tree)
836836
}
837837

838838
/** { stats; <empty > }

compiler/src/dotty/tools/dotc/config/Settings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ object Settings {
144144
Path(arg) match {
145145
case _: Directory =>
146146
update(arg, args)
147-
case p if p.extension == "jar" =>
147+
case p if p.`extension` == "jar" =>
148148
update(arg, args)
149149
case _ =>
150150
fail(s"'$arg' does not exist or is not a directory", args)

compiler/src/dotty/tools/dotc/fromtasty/Debug.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Debug {
3636
val fromTastyOut = Files.createDirectory(tmpOut.resolve("from-tasty"))
3737

3838
val ext = "hasTasty"
39-
val classes = Directory(fromSourcesOut).walk.filter(x => x.isFile && x.extension == ext).map { x =>
39+
val classes = Directory(fromSourcesOut).walk.filter(x => x.isFile && x.`extension` == ext).map { x =>
4040
val source = x.toString
4141
// transform foo/bar/Baz.hasTasty into foo.bar.Baz
4242
source.substring(fromSourcesOut.toString.length + 1, source.length - ext.length - 1).replace('/', '.')

compiler/src/dotty/tools/io/AbstractFile.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
9393
def canonicalPath: String = if (jpath == null) path else jpath.normalize.toString
9494

9595
/** Checks extension case insensitively. */
96-
def hasExtension(other: String) = extension == other.toLowerCase
97-
private val extension: String = Path.extension(name)
96+
def hasExtension(other: String) = `extension` == other.toLowerCase
97+
private val `extension`: String = Path.`extension`(name)
9898

9999
/** The absolute file, if this is a relative file. */
100100
def absolute: AbstractFile
@@ -122,7 +122,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
122122
}
123123

124124
/** Does this abstract file represent something which can contain classfiles? */
125-
def isClassContainer = isDirectory || (jpath != null && (extension == "jar" || extension == "zip"))
125+
def isClassContainer = isDirectory || (jpath != null && (`extension` == "jar" || `extension` == "zip"))
126126

127127
/** Create a file on disk, if one does not exist already. */
128128
def create(): Unit

compiler/src/dotty/tools/io/JarArchive.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class JarArchive private (root: Directory) extends PlainDirectory(root) {
1515
object JarArchive {
1616
/** Create a new jar file. Overwrite if file already exists */
1717
def create(path: Path): JarArchive = {
18-
require(path.extension == "jar")
18+
require(path.`extension` == "jar")
1919
path.delete()
2020
open(path, create = true)
2121
}
2222

2323
/** Create a jar file. */
2424
def open(path: Path, create: Boolean = false): JarArchive = {
25-
require(path.extension == "jar")
25+
require(path.`extension` == "jar")
2626

2727
// creating a new zip file system by using the JAR URL syntax:
2828
// https://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html

compiler/src/dotty/tools/io/Path.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import scala.util.Random.alphanumeric
3535
object Path {
3636
def isExtensionJarOrZip(jpath: JPath): Boolean = isExtensionJarOrZip(jpath.getFileName.toString)
3737
def isExtensionJarOrZip(name: String): Boolean = {
38-
val ext = extension(name)
38+
val ext = `extension`(name)
3939
ext == "jar" || ext == "zip"
4040
}
41-
def extension(name: String): String = {
41+
def `extension`(name: String): String = {
4242
var i = name.length - 1
4343
while (i >= 0 && name.charAt(i) != '.')
4444
i -= 1
@@ -138,7 +138,7 @@ class Path private[io] (val jpath: JPath) {
138138
if (p isSame this) Nil else p :: p.parents
139139
}
140140
// if name ends with an extension (e.g. "foo.jpg") returns the extension ("jpg"), otherwise ""
141-
def extension: String = {
141+
def `extension`: String = {
142142
var i = name.length - 1
143143
while (i >= 0 && name.charAt(i) != '.')
144144
i -= 1
@@ -148,17 +148,17 @@ class Path private[io] (val jpath: JPath) {
148148
}
149149
// compares against extensions in a CASE INSENSITIVE way.
150150
def hasExtension(ext: String, exts: String*) = {
151-
val lower = extension.toLowerCase
151+
val lower = `extension`.toLowerCase
152152
ext.toLowerCase == lower || exts.exists(_.toLowerCase == lower)
153153
}
154154
// returns the filename without the extension.
155-
def stripExtension: String = name stripSuffix ("." + extension)
155+
def stripExtension: String = name stripSuffix ("." + `extension`)
156156
// returns the Path with the extension.
157157
def addExtension(ext: String): Path = new Path(jpath.resolveSibling(name + ext))
158158
// changes the existing extension out for a new one, or adds it
159159
// if the current path has none.
160160
def changeExtension(ext: String): Path =
161-
if (extension == "") addExtension(ext)
161+
if (`extension` == "") addExtension(ext)
162162
else new Path(jpath.resolveSibling(stripExtension + "." + ext))
163163

164164
// conditionally execute

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class PatmatExhaustivityTest {
4545
val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer))
4646

4747
val files = Directory(path).list.toList
48-
.filter(f => f.extension == "scala" || f.extension == "java" )
48+
.filter(f => f.`extension` == "scala" || f.`extension` == "java" )
4949
.map(_.jpath.toString)
5050

5151
try {
@@ -69,7 +69,7 @@ class PatmatExhaustivityTest {
6969
@Test
7070
def patmatExhaustivity: Unit = {
7171
val res = Directory(testsDir).list.toList
72-
.filter(f => f.extension == "scala" || f.isDirectory)
72+
.filter(f => f.`extension` == "scala" || f.isDirectory)
7373
.map { f =>
7474
if (f.isDirectory)
7575
compileDir(f.jpath)

tests/neg/i2494.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
enum
1+
enum // error
22
object // error // error

tests/pos/t8306.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Si8306 {
22
def foo: Int = 123
3-
lazy val extension: Int =
3+
lazy val ext: Int =
44
foo match {
55
case idx if idx != -1 => 15
66
case _ => 17

0 commit comments

Comments
 (0)