Skip to content

Disable named type arguments by default #9982

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 3 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ object Feature:
def dependentEnabled(using Context) =
enabled(nme.dependent, defn.LanguageExperimentalModule.moduleClass)

def namedTypeArgsEnabled(using Context) =
enabled(nme.namedTypeArguments, defn.LanguageExperimentalModule.moduleClass)

def scala2ExperimentalMacroEnabled(using Context) =
enabled("macros".toTermName, defn.LanguageExperimentalModule.moduleClass)

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ object StdNames {
val moduleClass : N = "moduleClass"
val name: N = "name"
val nameDollar: N = "$name"
val namedTypeArguments: N = "namedTypeArguments"
val ne: N = "ne"
val newFreeTerm: N = "newFreeTerm"
val newFreeType: N = "newFreeType"
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,11 @@ trait Applications extends Compatibility {

def typedNamedArgs(args: List[untpd.Tree])(using Context): List[NamedArg] =
for (arg @ NamedArg(id, argtpt) <- args) yield {
if !Feature.namedTypeArgsEnabled then
report.error(
i"""Named type arguments are experimental,
|they must be enabled with a `experimental.namedTypeArguments` language import or setting""",
arg.srcPos)
val argtpt1 = typedType(argtpt)
cpy.NamedArg(arg)(id, argtpt1).withType(argtpt1.tpe)
}
Expand Down
9 changes: 3 additions & 6 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ SimpleType ::= SimpleLiteral
SimpleType1 ::= id Ident(name)
| Singleton ‘.’ id Select(t, name)
| Singleton ‘.’ ‘type’ SingletonTypeTree(p)
| ‘(’ ArgTypes ‘)’ Tuple(ts)
| ‘(’ Types ‘)’ Tuple(ts)
| Refinement RefinedTypeTree(EmptyTree, refinement)
| ‘$’ ‘{’ Block ‘}’
| SimpleType1 TypeArgs AppliedTypeTree(t, args)
Expand All @@ -170,16 +170,13 @@ Singleton ::= SimpleRef
| SimpleLiteral
| Singleton ‘.’ id
-- not yet | Singleton ‘(’ Singletons ‘)’
-- not yet | Singleton ‘[’ ArgTypes ‘]’
-- not yet | Singleton ‘[’ Types ‘]’
Singletons ::= Singleton { ‘,’ Singleton }
ArgTypes ::= Types
FunArgType ::= Type
| ‘=>’ Type PrefixOp(=>, t)
ParamType ::= [‘=>’] ParamValueType
ParamValueType ::= Type [‘*’] PostfixOp(t, "*")
TypeArgs ::= ‘[’ ArgTypes ‘]’ ts
NamedTypeArg ::= id ‘=’ Type NamedArg(id, t)
NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ nts
TypeArgs ::= ‘[’ Types ‘]’ ts
Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds
TypeBounds ::= [‘>:’ Type] [‘<:’ Type] TypeBoundsTree(lo, hi)
TypeParamBounds ::= TypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
Expand Down
6 changes: 3 additions & 3 deletions library/src/scalaShadowing/language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ object language {

/** Experimental support for richer dependent types */
object dependent

/** Experimental support for named type arguments */
object namedTypeArguments
}

/** Where imported, a backwards compatibility mode for Scala2 is enabled */
Expand Down Expand Up @@ -242,9 +245,6 @@ object language {
*/
object adhocExtensions

/** Experimental support for richer dependent types */
object dependent

/** Source version */
object `3.0-migration`
object `3.0`
Expand Down
1 change: 1 addition & 0 deletions tests/neg/i2771.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
trait A { type L[X] }
trait B { type L }
trait C { type M <: A }
Expand Down
1 change: 1 addition & 0 deletions tests/neg/i5328.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
class C[X, Y] { def apply[Z](x: X, y: Y, z: Z) = (x, y, z) }

object Test {
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/namedTypeParams.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
class C[T]
class D[type T] // error: identifier expected, but `type` found

object Test0:
def f[X, Y](x: X, y: Y): Int = ???
f[X = Int, Y = Int](1, 2) // error: experimental // error: experimental

object Test {
import language.experimental.namedTypeArguments

val x: C[T = Int] = // error: ']' expected, but `=` found // error
new C[T = Int] // error: ']' expected, but `=` found // error
Expand Down
1 change: 1 addition & 0 deletions tests/pos-custom-args/erased/i7868.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
import scala.compiletime._

final case class Coproduct[+Set, +Value, Index <: Int](value: Value & Set, index: Index)
Expand Down
1 change: 1 addition & 0 deletions tests/pos/gadt-GadtStlc.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object GadtStlc {
// creates type-level "strings" like M[M[M[W]]]
object W
Expand Down
1 change: 1 addition & 0 deletions tests/pos/gadt-TypeSafeLambda.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object TypeSafeLambda {

trait Category[Arr[_, _]] {
Expand Down
1 change: 1 addition & 0 deletions tests/pos/i3666-gadt.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object i3666 {
sealed trait Exp[T]
case class Num(n: Int) extends Exp[Int]
Expand Down
1 change: 1 addition & 0 deletions tests/pos/i3955.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object Foo {
inline def f[S, T](x: S): T = ???
def g(x: Int) = f[T = Any](x)
Expand Down
1 change: 1 addition & 0 deletions tests/pos/i5328.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
class C[X, Y] { def apply[Z](x: X, y: Y, z: Z) = (x, y, z) }

object Test {
Expand Down
1 change: 1 addition & 0 deletions tests/pos/kindPolySemiGroup.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Adapted from github:mandubian/kind-polymorphic-semigroup.scala
import language.experimental.namedTypeArguments
sealed trait HList
case class HCons[+HD, +TL](hd: HD, tl: TL) extends HList
case object HNil extends HList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
package namedTypeArgsR {

object t1 {
Expand Down
1 change: 1 addition & 0 deletions tests/pos/namedTypeParams.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object Test {

def f[X, Y](x: X, y: Y): Int = ???
Expand Down
1 change: 1 addition & 0 deletions tests/pos/t1513a.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object Test {
// Heterogeneous lists and natural numbers as defined in shapeless.

Expand Down
1 change: 1 addition & 0 deletions tests/pos/t1513b.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object Test {
def f[
T1 <: String,
Expand Down
1 change: 1 addition & 0 deletions tests/pos/typeclass-encoding3.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object Test {

/* --------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions tests/run-staging/staged-streams_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import scala.quoted._
import scala.quoted.staging._
import scala.quoted.util._
import language.experimental.namedTypeArguments

/**
* Port of the strymonas library as described in O. Kiselyov et al., Stream fusion, to completeness (POPL 2017)
*/
Expand Down
1 change: 1 addition & 0 deletions tests/run/creator-applys.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object Test extends App {
class A {
def run = "A"
Expand Down
1 change: 1 addition & 0 deletions tests/run/hmap-covariant.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
trait Tuple
case class TCons[+H, +T <: Tuple](h: H, t: T) extends Tuple
case object TNil extends Tuple
Expand Down
2 changes: 2 additions & 0 deletions tests/run/hmap.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import language.experimental.namedTypeArguments

trait Tuple
case class TCons[H, T <: Tuple](h: H, t: T) extends Tuple
case object TNil extends Tuple
Expand Down
1 change: 1 addition & 0 deletions tests/run/polymorphic-functions.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import language.experimental.namedTypeArguments
object Test extends App {
// Types
type F0 = [T] => List[T] => Option[T]
Expand Down