Skip to content

Commit c677aae

Browse files
committed
Enable kind polimorphism
Enable kind polimorphism by default by replacing `-Ykind-polymorphism` with `-Yno-kind-polymorphism`.
1 parent 8f6f3c1 commit c677aae

File tree

16 files changed

+17
-23
lines changed

16 files changed

+17
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class ScalaSettings extends Settings.SettingGroup {
138138
//.withPostSetHook( _ => YprofileEnabled.value = true )
139139

140140
// Extremely experimental language features
141-
val YkindPolymorphism: Setting[Boolean] = BooleanSetting("-Ykind-polymorphism", "Enable kind polymorphism (see http://dotty.epfl.ch/docs/reference/kind-polymorphism.html). Potentially unsound.")
141+
val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting("-Yno-kind-polymorphism", "Enable kind polymorphism (see http://dotty.epfl.ch/docs/reference/kind-polymorphism.html). Potentially unsound.")
142142

143143
/** Area-specific debug output */
144144
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class Definitions {
320320

321321
lazy val AnyKindClass: ClassSymbol = {
322322
val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil)
323-
if (ctx.settings.YkindPolymorphism.value) {
323+
if (!ctx.settings.YnoKindPolymorphism.value) {
324324
// Enable kind-polymorphism by exposing scala.AnyKind
325325
cls.entered
326326
}

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class CompilationTests extends ParallelTesting {
9191
compileFilesInDir("tests/pos-scala2", scala2Mode) +
9292
compileFilesInDir("tests/pos", defaultOptions) +
9393
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes) +
94-
compileFilesInDir("tests/pos-kind-polymorphism", defaultOptions and "-Ykind-polymorphism") +
9594
compileFile(
9695
// succeeds despite -Xfatal-warnings because of -nowarn
9796
"tests/neg-custom-args/fatal-warnings/xfatalWarnings.scala",
@@ -145,7 +144,7 @@ class CompilationTests extends ParallelTesting {
145144
implicit val testGroup: TestGroup = TestGroup("compileNeg")
146145
compileFilesInDir("tests/neg", defaultOptions) +
147146
compileFilesInDir("tests/neg-tailcall", defaultOptions) +
148-
compileFilesInDir("tests/neg-kind-polymorphism", defaultOptions and "-Ykind-polymorphism") +
147+
compileFilesInDir("tests/neg-no-kind-polymorphism", defaultOptions and "-Yno-kind-polymorphism") +
149148
compileFilesInDir("tests/neg-custom-args/deprecation", defaultOptions.and("-Xfatal-warnings", "-deprecation")) +
150149
compileFilesInDir("tests/neg-custom-args/fatal-warnings", defaultOptions.and("-Xfatal-warnings")) +
151150
compileFilesInDir("tests/neg-custom-args/allow-double-bindings", allowDoubleBindings) +

compiler/test/dotty/tools/repl/ReplTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.junit.{After, Before}
1010

1111

1212
class ReplTest private (out: ByteArrayOutputStream) extends ReplDriver(
13-
Array("-classpath", TestConfiguration.basicClasspath, "-color:never"),
13+
Array("-classpath", TestConfiguration.basicClasspath, "-color:never", "-Ykind-polymorphism"),
1414
new PrintStream(out)
1515
) with MessageRendering {
1616

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object TestConfiguration {
4747
val yCheckOptions = Array("-Ycheck:all")
4848

4949
val commonOptions = checkOptions ++ noCheckOptions ++ yCheckOptions
50-
val defaultOptions = TestFlags(basicClasspath, commonOptions) and "-Ykind-polymorphism" // FIXME remove "-Ykind-polymorphism"
50+
val defaultOptions = TestFlags(basicClasspath, commonOptions)
5151
val withCompilerOptions =
5252
defaultOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
5353
val allowDeepSubtypes = defaultOptions without "-Yno-deep-subtypes"

docs/docs/reference/other-new-features/kind-polymorphism.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ It is declared `abstract` and `final`, so it can be neither instantiated nor ext
4242

4343
`AnyKind` plays a special role in Scala's subtype system: It is a supertype of all other types no matter what their kind is. It is also assumed to be kind-compatible with all other types. Furthermore, `AnyKind` is treated as a higher-kinded type (so it cannot be used as a type of values), but at the same time it has no type parameters (so it cannot be instantiated).
4444

45-
**Note**: This feature is considered experimental and is only enabled under a compiler flag
46-
(i.e. `-Ykind-polymorphism`).
45+
**Note**: This feature is considered experimental but stable and it can be disabled under compiler flag
46+
(i.e. `-Yno-kind-polymorphism`).

library/src-non-bootstrapped/scala/tasty/reflect/QuotedOps.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ trait QuotedOps extends Core {
99
}
1010
implicit def QuotedExprDeco[T](expr: quoted.Expr[T]): QuotedExprAPI
1111

12-
trait QuotedTypeAPI {
12+
implicit class QuotedTypeDeco[T](tpe: quoted.Type[T]) {
1313
/** View this expression `Type[T]` as a `TypeTree` */
14-
def unseal(implicit ctx: Context): TypeTree
15-
}
16-
implicit def QuotedTypeDeco[T](tpe: quoted.Type[T]): QuotedTypeAPI = new QuotedTypeAPI {
17-
override def unseal(implicit ctx: Context): TypeTree = unsealType(tpe)
14+
def unseal(implicit ctx: Context): TypeTree = unsealType(tpe)
1815
}
1916

2017
protected def unsealType(tpe: quoted.Type[_])(implicit ctx: Context): TypeTree
2118

22-
trait TermToQuotedAPI {
19+
implicit class TermToQuoteDeco(term: Term) {
2320
/** Convert `Term` to an `Expr[T]` and check that it conforms to `T` */
24-
def seal[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T]
21+
def seal[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T] =
22+
sealTerm(term, unsealType(implicitly[scala.quoted.Type[T]])).asInstanceOf[scala.quoted.Expr[T]]
2523
}
26-
implicit def TermToQuoteDeco(term: Term): TermToQuotedAPI
24+
25+
protected def sealTerm(term: Term, tpt: TypeTree)(implicit ctx: Context): scala.quoted.Expr[_]
2726

2827
trait TypeToQuotedAPI {
2928
/** Convert `Type` to an `quoted.Type[T]` */

project/Build.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,17 +1135,11 @@ object Build {
11351135
def asDottyCompiler(implicit mode: Mode): Project = project.withCommonSettings.
11361136
dependsOn(`dotty-interfaces`).
11371137
dependsOn(dottyLibrary).
1138-
settings(dottyCompilerSettings).
1139-
bootstrappedSettings(
1140-
// To support kind polymorphism of scala.quote.Type
1141-
scalacOptions in Compile += "-Ykind-polymorphism"
1142-
)
1138+
settings(dottyCompilerSettings)
11431139

11441140
def asDottyLibrary(implicit mode: Mode): Project = project.withCommonSettings.
11451141
settings(dottyLibrarySettings).
11461142
bootstrappedSettings(
1147-
// To support kind polymorphism of scala.quote.Type
1148-
scalacOptions in Compile += "-Ykind-polymorphism",
11491143
// Needed so that the library sources are visible when `dotty.tools.dotc.core.Definitions#init` is called.
11501144
scalacOptions in Compile ++= Seq("-sourcepath", (scalaSource in Compile).value.getAbsolutePath)
11511145
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
trait Foo[T <: AnyKind] // Error: Not found: type AnyKind
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)