Skip to content

Commit

Permalink
Deprecate with type operator in 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 6, 2023
1 parent 5623c1b commit 865628d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 17 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
/** mods object name impl */
case class ModuleDef(name: TermName, impl: Template)(implicit @constructorOnly src: SourceFile)
extends MemberDef {
type ThisTree[+T <: Untyped] <: Trees.NameTree[T] with Trees.MemberDef[T] with ModuleDef
type ThisTree[+T <: Untyped] <: Trees.NameTree[T] & Trees.MemberDef[T] & ModuleDef
def withName(name: Name)(using Context): ModuleDef = cpy.ModuleDef(this)(name.toTermName, impl)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/CliCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.PartialFunction.cond

trait CliCommand:

type ConcreteSettings <: CommonScalaSettings with Settings.SettingGroup
type ConcreteSettings <: CommonScalaSettings & Settings.SettingGroup

def versionMsg: String

Expand Down
14 changes: 8 additions & 6 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1756,12 +1756,14 @@ object Parsers {
if in.token == LBRACE || in.token == INDENT then
t
else
report.errorOrMigrationWarning(
DeprecatedWithOperator(rewriteNotice(`future-migration`)),
in.sourcePos(withOffset),
from = future)
if sourceVersion == `future-migration` then
patch(source, Span(withOffset, withOffset + 4), "&")
val withSpan = Span(withOffset, withOffset + 4)
report.gradualErrorOrMigrationWarning(
DeprecatedWithOperator(rewriteNotice(`3.4-migration`)),
source.atSpan(withSpan),
warnFrom = `3.4`,
errorFrom = future)
if sourceVersion.isAtLeast(`3.4-migration`) then
patch(source, withSpan, "&")
atSpan(startOffset(t)) { makeAndType(t, withType()) }
else t

Expand Down
9 changes: 7 additions & 2 deletions compiler/test-resources/repl/i6643
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
scala> import scala.collection._

scala>:type 1
Int

scala> object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
// defined object IterableTest
21 changes: 21 additions & 0 deletions compiler/test-resources/type-printer/infix
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,31 @@ def foo: Int && Boolean & String
scala> def foo: Int && (Boolean & String) = ???
def foo: Int && (Boolean & String)
scala> def foo: Int && (Boolean with String) = ???
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | def foo: Int && (Boolean with String) = ???
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
def foo: Int && (Boolean & String)
scala> def foo: (Int && Boolean) with String = ???
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | def foo: (Int && Boolean) with String = ???
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
def foo: Int && Boolean & String
scala> def foo: Int && Boolean with String = ???
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | def foo: Int && Boolean with String = ???
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
def foo: Int && (Boolean & String)
scala> def foo: Int && Boolean | String = ???
def foo: Int && Boolean | String
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i2887b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ trait C { type M <: B }
trait D { type M >: A }

object Test {
def test(x: C with D): Unit = {
def test(x: C & D): Unit = {
def foo(a: A, b: B)(z: a.S[b.I,a.I][b.S[a.I,a.I]]) = z
def bar(a: A, y: x.M) = foo(a,y)
def baz(a: A) = bar(a, a)
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/with-type-operator-future-migration.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
5 |def foo: Int with String = ??? // error
| ^
| with as a type operator has been deprecated; use & instead
| This construct can be rewritten automatically under -rewrite -source future-migration.
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|
| longer explanation available when compiling with `-explain`
4 changes: 3 additions & 1 deletion tests/pos-deep-subtype/3324h.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//> using options -Xfatal-warnings

import scala.language.`3.3`

object Test {
trait Marker
def foo[T](x: T) = x match {
Expand All @@ -8,7 +10,7 @@ object Test {
}

def foo2[T](x: T) = x match {
case _: T with Marker => // scalac emits a warning
case _: T with Marker => // scalac or 3.4 emits a warning
case _ =>
}
}
5 changes: 5 additions & 0 deletions tests/pos/with-type-operator-3.3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//> using options -Werror

import scala.language.`3.3`

def foo: Int with String = ???
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//> using options -Werror
import scala.language.`3.4-migration`

def foo: Int with String = ??? // warn
3 changes: 0 additions & 3 deletions tests/pos/with-type-operator-future-migration.scala

This file was deleted.

0 comments on commit 865628d

Please sign in to comment.