Skip to content

Commit 865628d

Browse files
committed
Deprecate with type operator in 3.4
1 parent 5623c1b commit 865628d

File tree

11 files changed

+49
-17
lines changed

11 files changed

+49
-17
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
4242
/** mods object name impl */
4343
case class ModuleDef(name: TermName, impl: Template)(implicit @constructorOnly src: SourceFile)
4444
extends MemberDef {
45-
type ThisTree[+T <: Untyped] <: Trees.NameTree[T] with Trees.MemberDef[T] with ModuleDef
45+
type ThisTree[+T <: Untyped] <: Trees.NameTree[T] & Trees.MemberDef[T] & ModuleDef
4646
def withName(name: Name)(using Context): ModuleDef = cpy.ModuleDef(this)(name.toTermName, impl)
4747
}
4848

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scala.PartialFunction.cond
1212

1313
trait CliCommand:
1414

15-
type ConcreteSettings <: CommonScalaSettings with Settings.SettingGroup
15+
type ConcreteSettings <: CommonScalaSettings & Settings.SettingGroup
1616

1717
def versionMsg: String
1818

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,12 +1756,14 @@ object Parsers {
17561756
if in.token == LBRACE || in.token == INDENT then
17571757
t
17581758
else
1759-
report.errorOrMigrationWarning(
1760-
DeprecatedWithOperator(rewriteNotice(`future-migration`)),
1761-
in.sourcePos(withOffset),
1762-
from = future)
1763-
if sourceVersion == `future-migration` then
1764-
patch(source, Span(withOffset, withOffset + 4), "&")
1759+
val withSpan = Span(withOffset, withOffset + 4)
1760+
report.gradualErrorOrMigrationWarning(
1761+
DeprecatedWithOperator(rewriteNotice(`3.4-migration`)),
1762+
source.atSpan(withSpan),
1763+
warnFrom = `3.4`,
1764+
errorFrom = future)
1765+
if sourceVersion.isAtLeast(`3.4-migration`) then
1766+
patch(source, withSpan, "&")
17651767
atSpan(startOffset(t)) { makeAndType(t, withType()) }
17661768
else t
17671769

compiler/test-resources/repl/i6643

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
scala> import scala.collection._
2-
32
scala>:type 1
43
Int
5-
64
scala> object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
5+
1 warning found
6+
-- [E003] Syntax Warning: ------------------------------------------------------
7+
1 | object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
8+
| ^^^^
9+
| with as a type operator has been deprecated; use & instead
10+
|
11+
| longer explanation available when compiling with `-explain`
712
// defined object IterableTest

compiler/test-resources/type-printer/infix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,31 @@ def foo: Int && Boolean & String
4848
scala> def foo: Int && (Boolean & String) = ???
4949
def foo: Int && (Boolean & String)
5050
scala> def foo: Int && (Boolean with String) = ???
51+
1 warning found
52+
-- [E003] Syntax Warning: ------------------------------------------------------
53+
1 | def foo: Int && (Boolean with String) = ???
54+
| ^^^^
55+
| with as a type operator has been deprecated; use & instead
56+
|
57+
| longer explanation available when compiling with `-explain`
5158
def foo: Int && (Boolean & String)
5259
scala> def foo: (Int && Boolean) with String = ???
60+
1 warning found
61+
-- [E003] Syntax Warning: ------------------------------------------------------
62+
1 | def foo: (Int && Boolean) with String = ???
63+
| ^^^^
64+
| with as a type operator has been deprecated; use & instead
65+
|
66+
| longer explanation available when compiling with `-explain`
5367
def foo: Int && Boolean & String
5468
scala> def foo: Int && Boolean with String = ???
69+
1 warning found
70+
-- [E003] Syntax Warning: ------------------------------------------------------
71+
1 | def foo: Int && Boolean with String = ???
72+
| ^^^^
73+
| with as a type operator has been deprecated; use & instead
74+
|
75+
| longer explanation available when compiling with `-explain`
5576
def foo: Int && (Boolean & String)
5677
scala> def foo: Int && Boolean | String = ???
5778
def foo: Int && Boolean | String

tests/neg/i2887b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait C { type M <: B }
44
trait D { type M >: A }
55

66
object Test {
7-
def test(x: C with D): Unit = {
7+
def test(x: C & D): Unit = {
88
def foo(a: A, b: B)(z: a.S[b.I,a.I][b.S[a.I,a.I]]) = z
99
def bar(a: A, y: x.M) = foo(a,y)
1010
def baz(a: A) = bar(a, a)

tests/neg/with-type-operator-future-migration.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
5 |def foo: Int with String = ??? // error
33
| ^
44
| with as a type operator has been deprecated; use & instead
5-
| This construct can be rewritten automatically under -rewrite -source future-migration.
5+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
66
|
77
| longer explanation available when compiling with `-explain`

tests/pos-deep-subtype/3324h.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//> using options -Xfatal-warnings
22

3+
import scala.language.`3.3`
4+
35
object Test {
46
trait Marker
57
def foo[T](x: T) = x match {
@@ -8,7 +10,7 @@ object Test {
810
}
911

1012
def foo2[T](x: T) = x match {
11-
case _: T with Marker => // scalac emits a warning
13+
case _: T with Marker => // scalac or 3.4 emits a warning
1214
case _ =>
1315
}
1416
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//> using options -Werror
2+
3+
import scala.language.`3.3`
4+
5+
def foo: Int with String = ???
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
//> using options -Werror
1+
import scala.language.`3.4-migration`
22

33
def foo: Int with String = ??? // warn

tests/pos/with-type-operator-future-migration.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)