-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #11774: only enable experimental features for snapshot and nightly #11852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
75a615f
Fix #11774: only enable experimental features for snapshot and nightly
liufengyun c6f250a
Test with -Yno-experimental
liufengyun b6902b9
Macros are not experimental
liufengyun 0e39cce
Remove experimental flag in stdlib
liufengyun 7ffbbc7
Reorganize tests
liufengyun 134efe5
Disable -Yno-experimental temporarily
liufengyun 4bf8678
Add more tests
liufengyun 2b96803
Fix compiler version (unknown) in community build
liufengyun b678f83
Only test scodec with experimental compiler
liufengyun 0427c23
Fix CI
liufengyun a20d83d
Address review
liufengyun 9f62255
Reorganize tests
liufengyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,19 @@ object Feature: | |
val symbolLiterals = deprecated("symbolLiterals") | ||
val fewerBraces = experimental("fewerBraces") | ||
|
||
/** Is `feature` enabled by by a command-line setting? The enabling setting is | ||
val experimentalWarningMessage = "Experimental features may only be used with nightly or snapshot version of compiler." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should refine the message by saying that Scala 3 |
||
|
||
/** Experimental features are only enabled for snapshot and nightly compiler versions | ||
*/ | ||
def experimentalEnabled(using Context): Boolean = | ||
Properties.experimental && !ctx.settings.YnoExperimental.value | ||
|
||
def isExperimental(feature: TermName): Boolean = | ||
feature != scala2macros && feature.match | ||
case QualifiedName(nme.experimental, _) => true | ||
case _ => false | ||
|
||
/** Is `feature` enabled by by a command-line setting? The enabling setting is | ||
* | ||
* -language:<prefix>feature | ||
* | ||
|
@@ -56,9 +68,12 @@ object Feature: | |
* @param feature The name of the feature | ||
* @param owner The prefix symbol (nested in `scala.language`) where the | ||
* feature is defined. | ||
* | ||
* Note: Experimental features are only enabled for snapshot and nightly version of compiler. | ||
*/ | ||
def enabled(feature: TermName)(using Context): Boolean = | ||
enabledBySetting(feature) || enabledByImport(feature) | ||
(experimentalEnabled || !isExperimental(feature)) | ||
&& (enabledBySetting(feature) || enabledByImport(feature)) | ||
|
||
/** Is auto-tupling enabled? */ | ||
def autoTuplingEnabled(using Context): Boolean = !enabled(nme.noAutoTupling) | ||
|
@@ -71,6 +86,8 @@ object Feature: | |
|
||
def genericNumberLiteralsEnabled(using Context) = enabled(genericNumberLiterals) | ||
|
||
def erasedEnabled(using Context) = enabled(Feature.erasedDefinitions) | ||
|
||
def scala2ExperimentalMacroEnabled(using Context) = enabled(scala2macros) | ||
|
||
def sourceVersionSetting(using Context): SourceVersion = | ||
|
@@ -97,4 +114,16 @@ object Feature: | |
else | ||
false | ||
|
||
/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */ | ||
def checkExperimentalFlags(using Context): Unit = | ||
if !experimentalEnabled then | ||
val features = ctx.settings.language.value.filter { feature => | ||
feature.contains(nme.experimental.toString) && !feature.contains("macros") | ||
} | ||
if features.nonEmpty then | ||
report.error( | ||
experimentalWarningMessage + | ||
"\nThe experimental language features are enabled via -language:" + features.mkString(",") | ||
) | ||
|
||
end Feature |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...g-custom-args/typeclass-derivation2.scala → ...m-args/erased/typeclass-derivation2.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import language.experimental.erasedDefinitions | ||
|
||
import scala.collection.mutable | ||
import scala.annotation.tailrec | ||
|
||
|
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,3 @@ object BigFloat extends App { | |
'{BigInt(${Expr(x.toString)})} | ||
} | ||
} | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
tests/neg-custom-args/deptypes.scala → ...g-custom-args/experimental/deptypes.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import language.experimental.dependent | ||
|
||
type Vec[T] = (n: Int) =>> Array[T] // error: not yet implemented | ||
|
||
|
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,3 @@ erased trait D | |
|
||
val x = new A{} // ok, x is erased | ||
val y = new C with D{} // error | ||
|
||
|
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
class Test0 { | ||
import language.experimental.namedTypeArguments // error | ||
liufengyun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
object Foo { | ||
inline def f[S, T](x: S): T = ??? | ||
def g(x: Int) = f[T = Any](x) // error | ||
} | ||
} | ||
|
||
class Test1 { | ||
import language.experimental.erasedDefinitions // error | ||
import scala.compiletime.erasedValue | ||
type UnivEq[A] | ||
object UnivEq: | ||
erased def force[A]: UnivEq[A] = erasedValue // error // error // error | ||
extension [A](erased proof: UnivEq[A]) // error | ||
inline def univEq(a: A, b: A): Boolean = | ||
a == b | ||
} | ||
|
||
class Test2 { | ||
import scala.language.experimental.genericNumberLiterals // error | ||
val x: BigInt = 13232202002020202020202 // error | ||
val y: BigInt = -0xaabb12345ACF12345AC // error | ||
} | ||
|
||
class Test3 { | ||
import scala.language.experimental.namedTypeArguments // error | ||
object Foo { | ||
inline def f[S, T](x: S): T = ??? | ||
def g(x: Int) = f[T = Any](x) // error | ||
} | ||
} | ||
|
||
class Test4 { | ||
import scala.language.experimental.erasedDefinitions // error | ||
import scala.compiletime.erasedValue | ||
type UnivEq[A] | ||
object UnivEq: | ||
erased def force[A]: UnivEq[A] = erasedValue // error // error // error | ||
extension [A](erased proof: UnivEq[A]) // error | ||
inline def univEq(a: A, b: A): Boolean = | ||
a == b | ||
} | ||
|
||
class Test5 { | ||
import scala.language.experimental.genericNumberLiterals // error | ||
val x: BigInt = 13232202002020202020202 // error | ||
val y: BigInt = -0xaabb12345ACF12345AC // error | ||
} | ||
|
||
class Test6 { | ||
import scala.language.experimental | ||
} | ||
|
||
class Test7 { | ||
import scala.language.experimental | ||
import experimental.genericNumberLiterals // error: no aliases can be used to refer to a language import | ||
val x: BigInt = 13232202002020202020202 // error | ||
} |
19 changes: 0 additions & 19 deletions
19
tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
tests/pos/erased-class-separate/A_1.scala → ...erimental/erased-class-separate/A_1.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
import language.experimental.erasedDefinitions | ||
erased class A | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odersky FYI, putting
fewerBraces
underexperimental
means that it will only available for nightly build of compilers after this PR. Normal releases cannot use the feature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's understood.