Skip to content

Commit 24590a3

Browse files
committed
error when postfix and postfixOps not enabled
1 parent 764a23e commit 24590a3

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,11 @@ object desugar {
16771677
}
16781678
else {
16791679
assert(ctx.mode.isExpr || ctx.reporter.errorsReported || ctx.mode.is(Mode.Interactive), ctx.mode)
1680+
if (!ctx.featureEnabled(nme.postFixOps)) {
1681+
// TODO remove, only here to show that we are in the if-branch
1682+
println(s"======================================= here but does not error / scala2Compat: ${ctx.scala2CompatMode}")
1683+
ctx.errorOrMigrationWarning(s"Usage of postfix operator `${op.name}` in: ${t.show} ${op.name}", t.symbol.sourcePos)
1684+
}
16801685
Select(t, op.name)
16811686
}
16821687
case PrefixOp(op, t) =>

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ object StdNames {
538538
val ordinalDollar_ : N = "_$ordinal"
539539
val origin: N = "origin"
540540
val parts: N = "parts"
541+
val postFixOps: N = "postFixOps"
541542
val prefix : N = "prefix"
542543
val processEscapes: N = "processEscapes"
543544
val productArity: N = "productArity"

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
499499
if (!sym.exists) ""
500500
else toPrefix(sym.owner) + sym.name + "."
501501
val featureName = toPrefix(owner) + feature
502-
ctx.base.settings.language.value exists (s => s == featureName)
502+
ctx.base.settings.language.value contains featureName
503503
}
504504
hasOption || hasImport
505505
}

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ trait Reporting { this: Context =>
140140
def error(ex: TypeError, pos: SourcePosition): Unit = {
141141
error(ex.toMessage, pos, sticky = true)
142142
if (ctx.settings.YdebugTypeError.value)
143-
ex.printStackTrace
143+
ex.printStackTrace()
144144
}
145145

146146
def errorOrMigrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class CompilationTests extends ParallelTesting {
6464
compileFile("tests/pos-special/i7575.scala", defaultOptions.and("-language:dynamics")),
6565
compileFile("tests/pos-special/kind-projector.scala", defaultOptions.and("-Ykind-projector")),
6666
compileFile("tests/run/i5606.scala", defaultOptions.and("-Yretain-trees")),
67+
compileFile("tests/pos-custom-args/i5498-postfixOps.scala", defaultOptions.and("-language:postFixOps")),
68+
compileFile(
69+
// succeeds because only a warning in Scala2Compat mode
70+
"tests/pos-custom-args/i5498-postfixOps.scala",
71+
defaultOptions.and("-language:Scala2Compat")
72+
),
6773
).checkCompile()
6874
}
6975

tests/neg/i5498-postfixOps.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.concurrent.duration._
2+
3+
def test() = {
4+
1 second
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.concurrent.duration._
2+
3+
def test() = {
4+
1 second
5+
}

0 commit comments

Comments
 (0)