You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ya...@apache.org on 2023/10/26 05:18:38 UTC
[spark] branch master updated: [SPARK-44407][BUILD][TESTS] Clean up the compilation warnings related to `it will become a keyword in Scala 3` and prohibit use these keywords as variable name
This is an automated email from the ASF dual-hosted git repository.
yangjie01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 35c628d9b27 [SPARK-44407][BUILD][TESTS] Clean up the compilation warnings related to `it will become a keyword in Scala 3` and prohibit use these keywords as variable name
35c628d9b27 is described below
commit 35c628d9b27aee9263bf43254cd839da69da9f28
Author: yangjie01 <ya...@baidu.com>
AuthorDate: Thu Oct 26 13:18:23 2023 +0800
[SPARK-44407][BUILD][TESTS] Clean up the compilation warnings related 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 #43529 from LuciferYang/SPARK-44407.
Authored-by: yangjie01 <ya...@baidu.com>
Signed-off-by: yangjie01 <ya...@baidu.com>
---
pom.xml | 6 ++++++
project/SparkBuild.scala | 6 +++++-
.../org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala | 4 ++--
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index e3f3b2fe9a1..6488918326f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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&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&msg=it will become a keyword in Scala 3:e</arg>
</args>
<jvmArgs>
<jvmArg>-Xss128m</jvmArg>
diff --git a/project/SparkBuild.scala b/project/SparkBuild.scala
index 6e87cab6df8..098a628ba1c 100644
--- a/project/SparkBuild.scala
+++ b/project/SparkBuild.scala
@@ -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"
)
}
)
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala
index f7c1043d1cb..bef0cf8831e 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala
@@ -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] = _
@@ -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(
@@ -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),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org