From 121e28fe6300c033379926f6a68f87a2ee24e87a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 6 Nov 2023 11:06:46 +0100 Subject: [PATCH] Improve `with` in type migration warning --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 5 +++-- tests/neg/with-type-operator-future-migration.check | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index c845ea8f74c7..bbe701e4f3d6 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1756,12 +1756,13 @@ object Parsers { if in.token == LBRACE || in.token == INDENT then t else + val withSpan = Span(withOffset, withOffset + 4) report.errorOrMigrationWarning( DeprecatedWithOperator(rewriteNotice(`future-migration`)), - in.sourcePos(withOffset), + source.atSpan(withSpan), from = future) if sourceVersion == `future-migration` then - patch(source, Span(withOffset, withOffset + 4), "&") + patch(source, withSpan, "&") atSpan(startOffset(t)) { makeAndType(t, withType()) } else t diff --git a/tests/neg/with-type-operator-future-migration.check b/tests/neg/with-type-operator-future-migration.check index 29ea1d5aad4c..845601349c83 100644 --- a/tests/neg/with-type-operator-future-migration.check +++ b/tests/neg/with-type-operator-future-migration.check @@ -1,6 +1,6 @@ -- [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. |