Skip to content
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

Future migration warning for with type operator #18818

Merged
merged 1 commit into from
Nov 2, 2023
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
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1756,8 +1756,12 @@ object Parsers {
if in.token == LBRACE || in.token == INDENT then
t
else
if sourceVersion.isAtLeast(future) then
deprecationWarning(DeprecatedWithOperator(), withOffset)
report.errorOrMigrationWarning(
DeprecatedWithOperator(rewriteNotice(`future-migration`)),
in.sourcePos(withOffset),
from = future)
if sourceVersion == `future-migration` then
patch(source, Span(withOffset, withOffset + 4), "&")
atSpan(startOffset(t)) { makeAndType(t, withType()) }
else t

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ extends EmptyCatchOrFinallyBlock(tryBody, EmptyCatchAndFinallyBlockID) {
|its body in a block; no exceptions are handled."""
}

class DeprecatedWithOperator()(using Context)
class DeprecatedWithOperator(rewrite: String)(using Context)
extends SyntaxMsg(DeprecatedWithOperatorID) {
def msg(using Context) =
i"""${hl("with")} as a type operator has been deprecated; use ${hl("&")} instead"""
i"""${hl("with")} as a type operator has been deprecated; use ${hl("&")} instead$rewrite"""
def explain(using Context) =
i"""|Dotty introduces intersection types - ${hl("&")} types. These replace the
|use of the ${hl("with")} keyword. There are a few differences in
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CompilationTests {
compileFile("tests/rewrites/rewrites.scala", defaultOptions.and("-source", "3.0-migration").and("-rewrite", "-indent")),
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
compileFile("tests/rewrites/rewrites3x-fatal-warnings.scala", defaultOptions.and("-rewrite", "-source", "future-migration", "-Xfatal-warnings")),
compileFile("tests/rewrites/with-type-operator.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
compileFile("tests/rewrites/refutable-pattern-bindings.scala", defaultOptions.and("-rewrite", "-source", "3.2-migration")),
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/with-type-operator-future-migration.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E003] Syntax Error: tests/neg/with-type-operator-future-migration.scala:5:13 ---------------------------------------
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.
|
| longer explanation available when compiling with `-explain`
5 changes: 5 additions & 0 deletions tests/neg/with-type-operator-future-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//> using options -Werror

import scala.language.`future-migration`

def foo: Int with String = ??? // error
3 changes: 3 additions & 0 deletions tests/neg/with-type-operator-future.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import scala.language.`future`

def foo: Int with String = ??? // error
3 changes: 3 additions & 0 deletions tests/pos/with-type-operator-future-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import scala.language.`future-migration`

def foo: Int with String = ??? // warn
3 changes: 3 additions & 0 deletions tests/pos/with-type-operator.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//> using options -Werror

def foo: Int with String = ??? // warn
1 change: 1 addition & 0 deletions tests/rewrites/with-type-operator.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def foo: Int & String = ???
1 change: 1 addition & 0 deletions tests/rewrites/with-type-operator.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def foo: Int with String = ???
Loading