Skip to content

Commit

Permalink
[SPARK-44407][BUILD][TESTS] Clean up the compilation warnings related…
Browse files Browse the repository at this point in the history
… to `it will become a keyword in Scala 3` and prohibit use these keywords as variable name

### What changes were proposed in this pull request?
This pr clean up the compilation warnings related to `it will become a keyword in Scala 3`,  additionally, to facilitate future Scala version migration, a new compiler option has been added to prohibit the use of these keywords as variable names.

### Why are the changes needed?
There are some literals, such as `enum`, `given`, `export`, etc., using them as variable names in Scala 2.13 will trigger compilation warnings, but this will become a compilation error in Scala 3.

**Scala 2.13**

```
Welcome to Scala 2.13.12 (OpenJDK 64-Bit Server VM, Java 17.0.8).
Type in expressions for evaluation. Or try :help.

scala> val enum: Int = 1
           ^
       warning: Wrap `enum` in backticks to use it as an identifier, it will become a keyword in Scala 3. [quickfixable]
val enum: Int = 1

scala> val export: Int = 1
           ^
       warning: Wrap `export` in backticks to use it as an identifier, it will become a keyword in Scala 3. [quickfixable]
val export: Int = 1

scala> val given: Int = 1
           ^
       warning: Wrap `given` in backticks to use it as an identifier, it will become a keyword in Scala 3. [quickfixable]
val given: Int = 1
```

**Scala 3**

```
Welcome to Scala 3.3.1 (17.0.8, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> val enum: Int = 1
-- [E032] Syntax Error: --------------------------------------------------------
1 |val enum: Int = 1
  |    ^^^^
  |    pattern expected
  |
  | longer explanation available when compiling with `-explain`

scala> val export: Int = 1
-- [E032] Syntax Error: --------------------------------------------------------
1 |val export: Int = 1
  |    ^^^^^^
  |    pattern expected
  |
  | longer explanation available when compiling with `-explain`

scala> val given: Int = 1
-- [E040] Syntax Error: --------------------------------------------------------
1 |val given: Int = 1
  |         ^
  |         an identifier expected, but ':' found
  |
  | longer explanation available when compiling with `-explain`
```

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#43529 from LuciferYang/SPARK-44407.

Authored-by: yangjie01 <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
  • Loading branch information
LuciferYang committed Oct 26, 2023
1 parent 8cdcfd2 commit 35c628d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,12 @@
SPARK-45627 Symbol literals are deprecated in Scala 2.13 and it's a compile error in Scala 3.
-->
<arg>-Wconf:cat=deprecation&amp;msg=symbol literal is deprecated:e</arg>
<!--
SPARK-45627 `enum`, `export` and `given` will become keywords in Scala 3,
so they are prohibited from being used as variable names in Scala 2.13 to
reduce the cost of migration in subsequent versions.
-->
<arg>-Wconf:cat=deprecation&amp;msg=it will become a keyword in Scala 3:e</arg>
</args>
<jvmArgs>
<jvmArg>-Xss128m</jvmArg>
Expand Down
6 changes: 5 additions & 1 deletion project/SparkBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ object SparkBuild extends PomBuild {
// Or use `-Wconf:msg=legacy-binding:s` to silence this warning. [quickfixable]"
"-Wconf:msg=legacy-binding:s",
// SPARK-45627 Symbol literals are deprecated in Scala 2.13 and it's a compile error in Scala 3.
"-Wconf:cat=deprecation&msg=symbol literal is deprecated:e"
"-Wconf:cat=deprecation&msg=symbol literal is deprecated:e",
// SPARK-45627 `enum`, `export` and `given` will become keywords in Scala 3,
// so they are prohibited from being used as variable names in Scala 2.13 to
// reduce the cost of migration in subsequent versions.
"-Wconf:cat=deprecation&msg=it will become a keyword in Scala 3:e"
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LeafBean {
@BeanProperty var localDateTime: java.time.LocalDateTime = _
@BeanProperty var duration: java.time.Duration = _
@BeanProperty var period: java.time.Period = _
@BeanProperty var enum: java.time.Month = _
@BeanProperty var monthEnum: java.time.Month = _
@BeanProperty val readOnlyString = "read-only"
@BeanProperty var genericNestedBean: JavaBeanWithGenericBase = _
@BeanProperty var genericNestedBean2: JavaBeanWithGenericsABC[Integer] = _
Expand Down Expand Up @@ -186,7 +186,6 @@ class JavaTypeInferenceSuite extends SparkFunSuite {
encoderField("boxedShort", BoxedShortEncoder),
encoderField("date", STRICT_DATE_ENCODER),
encoderField("duration", DayTimeIntervalEncoder),
encoderField("enum", JavaEnumEncoder(classTag[java.time.Month])),
encoderField("genericNestedBean", JavaBeanEncoder(
ClassTag(classOf[JavaBeanWithGenericBase]),
Seq(
Expand All @@ -203,6 +202,7 @@ class JavaTypeInferenceSuite extends SparkFunSuite {
encoderField("instant", STRICT_INSTANT_ENCODER),
encoderField("localDate", STRICT_LOCAL_DATE_ENCODER),
encoderField("localDateTime", LocalDateTimeEncoder),
encoderField("monthEnum", JavaEnumEncoder(classTag[java.time.Month])),
encoderField("nonNullString", StringEncoder, overrideNullable = Option(false)),
encoderField("period", YearMonthIntervalEncoder),
encoderField("primitiveBoolean", PrimitiveBooleanEncoder),
Expand Down

0 comments on commit 35c628d

Please sign in to comment.