Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
13 changes: 0 additions & 13 deletions src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,6 @@ trait ContextErrors extends splain.SplainErrors {
setError(tree)
}

//typedEta
private def mkUnderscoreNullaryEtaMessage(what: String) =
s"Methods without a parameter list and by-name params can $what be converted to functions as `m _`, " +
"write a function literal `() => m` instead"

final val UnderscoreNullaryEtaWarnMsg = mkUnderscoreNullaryEtaMessage("no longer")
final val UnderscoreNullaryEtaErrorMsg = mkUnderscoreNullaryEtaMessage("not")

def UnderscoreNullaryEtaError(tree: Tree, actions: List[CodeAction]) = {
issueNormalTypeError(tree, UnderscoreNullaryEtaErrorMsg, actions)
setError(tree)
}

def UnderscoreEtaError(tree: Tree) = {
issueNormalTypeError(tree, "_ must follow method; cannot follow " + tree.tpe)
setError(tree)
Expand Down
189 changes: 105 additions & 84 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4016,7 +4016,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
return finish(ErroneousAnnotation)
}
if (currentRun.isScala3 && (/*annTypeSym.eq(SpecializedClass) ||*/ annTypeSym.eq(ElidableMethodClass)))
context.deprecationWarning(ann.pos, annTypeSym, s"@${annTypeSym.fullNameString} is ignored in Scala 3", "2.13.12")
context.warning(ann.pos, s"@${annTypeSym.fullNameString} is ignored in Scala 3", WarningCategory.Scala3Migration)

/* Calling constfold right here is necessary because some trees (negated
* floats and literals in particular) are not yet folded.
Expand Down Expand Up @@ -4972,19 +4972,22 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper

val result = typed(Function(Nil, methodValue) setSymbol funSym setPos pos, mode, pt)

val msg = "Methods without a parameter list and by-name params can no longer be converted to functions as `m _`, " +
"write a function literal `() => m` instead"

val action = {
val etaPos = pos.withEnd(pos.end + 2)
if (currentUnit.sourceAt(etaPos).endsWith(" _"))
runReporting.codeAction("replace by function literal", etaPos, s"() => ${currentUnit.sourceAt(pos)}", UnderscoreNullaryEtaWarnMsg)
runReporting.codeAction("replace by function literal", etaPos, s"() => ${currentUnit.sourceAt(pos)}", msg)
else Nil
}

if (currentRun.isScala3) {
UnderscoreNullaryEtaError(methodValue, action)
} else {
context.deprecationWarning(pos, NoSymbol, UnderscoreNullaryEtaWarnMsg, "2.13.2", action)
result
}
if (currentRun.isScala3)
context.warning(pos, msg, WarningCategory.Scala3Migration, action)
else
context.deprecationWarning(pos, NoSymbol, msg, "2.13.2", action)

result

case ErrorType =>
methodValue
Expand Down
6 changes: 3 additions & 3 deletions test/files/neg/deprecated-annots.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
deprecated-annots.scala:9: warning: @scala.annotation.elidable is ignored in Scala 3
deprecated-annots.scala:9: error: @scala.annotation.elidable is ignored in Scala 3
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=D
@annotation.elidable(42)
^
error: No warnings can be incurred under -Werror.
1 warning
1 error
14 changes: 13 additions & 1 deletion test/files/neg/nullary-override-3a.check
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
nullary-override-3a.scala:4: error: method with a single empty parameter list overrides method without any parameter list
def x: Int (defined in class A) [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=B
class B extends A { override def x(): Int = 4 }
^
nullary-override-3a.scala:16: error: method with a single empty parameter list overrides method without any parameter list
def x: String (defined in trait T1) [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=Mix12b
class Mix12b extends T1 with T2 { override def x() = "12b" }
^
nullary-override-3a.scala:18: error: method without a parameter list overrides a method with a single empty one
def x(): String (defined in trait T2) [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=Mix21a
class Mix21a extends T2 with T1 { override def x = "21a" }
^
nullary-override-3a.scala:19: error: method with a single empty parameter list overrides method without any parameter list
def x: String (defined in trait T1) [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=Mix21b
class Mix21b extends T2 with T1 { override def x() = "21b" }
^
3 errors
4 errors
4 changes: 4 additions & 0 deletions test/files/neg/nullary-override-3b.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
nullary-override-3b.scala:6: error: method without a parameter list overrides a method with a single empty one
def x(): Int (defined in class P) [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=Q
class Q extends P { override def x: Int = 4 }
^
nullary-override-3b.scala:11: error: method without a parameter list overrides a method with a single empty one
def x(): String (defined in trait T2) [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=Mix12a
class Mix12a extends T1 with T2 { override def x = "12a" }
^
2 errors
5 changes: 4 additions & 1 deletion test/files/neg/nullary-override.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class Mix12a extends T1 with T2 { override def x = "12a" }
nullary-override.scala:37: warning: method with a single empty parameter list overrides method without any parameter list [quickfixable]
class Mix12b extends T1 with T2 { override def x() = "12b" }
^
nullary-override.scala:39: warning: method without a parameter list overrides a method with a single empty one [quickfixable]
class Mix21a extends T2 with T1 { override def x = "21a" }
^
nullary-override.scala:40: warning: method with a single empty parameter list overrides method without any parameter list [quickfixable]
class Mix21b extends T2 with T1 { override def x() = "21b" }
^
error: No warnings can be incurred under -Werror.
5 warnings
6 warnings
1 error
9 changes: 9 additions & 0 deletions test/files/neg/t12851b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
C_2.scala:2: warning: method (method f in trait T2) with a single empty parameter list overrides method without any parameter list
class C extends T1 with T2
^
C_2.scala:2: warning: method (method g in trait T2) without a parameter list overrides a method with a single empty one
class C extends T1 with T2
^
error: No warnings can be incurred under -Werror.
2 warnings
1 error
2 changes: 2 additions & 0 deletions test/files/neg/t12851b/C_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// scalac: -Werror
class C extends T1 with T2
11 changes: 11 additions & 0 deletions test/files/neg/t12851b/T_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

trait T1 {
def f: Int
def g(): Int
def v(): Int
}
trait T2 {
def f() = 42
def g = 42
val v = 42
}
8 changes: 5 additions & 3 deletions test/files/neg/t7187-3.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ t7187-3.scala:16: error: type mismatch;
required: SamZero
val t2Sam: SamZero = m2 // error, nilary methods don't eta-expand to SAM types
^
t7187-3.scala:27: error: Methods without a parameter list and by-name params can not be converted to functions as `m _`, write a function literal `() => m` instead [quickfixable]
val t7 = m1 _ // error: eta-expanding a nullary method
^
t7187-3.scala:14: warning: An unapplied 0-arity method was eta-expanded (due to the expected type () => Any), rather than applied to `()`.
Write m2() to invoke method m2, or change the expected type.
val t2: () => Any = m2 // eta-expanded with lint warning
^
t7187-3.scala:27: error: Methods without a parameter list and by-name params can no longer be converted to functions as `m _`, write a function literal `() => m` instead [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=EtaExpand214.t7
val t7 = m1 _ // error: eta-expanding a nullary method
^
1 warning
4 errors
8 changes: 5 additions & 3 deletions test/files/neg/t7187-deprecation.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ t7187-deprecation.scala:20: error: type mismatch;
required: SamZero
val t2Sam: SamZero = m2 // error, nilary methods don't eta-expand to SAM types
^
t7187-deprecation.scala:31: error: Methods without a parameter list and by-name params can not be converted to functions as `m _`, write a function literal `() => m` instead [quickfixable]
val t7 = m1 _ // error: eta-expanding a nullary method
^
t7187-deprecation.scala:24: warning: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method m2,
or remove the empty argument list from its definition (Java-defined methods are exempt).
In Scala 3, an unapplied method like this will be eta-expanded into a function. [quickfixable]
val t5 = m2 // warn: apply, ()-insertion
^
t7187-deprecation.scala:31: error: Methods without a parameter list and by-name params can no longer be converted to functions as `m _`, write a function literal `() => m` instead [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=EtaExpand214.t7
val t7 = m1 _ // error: eta-expanding a nullary method
^
t7187-deprecation.scala:40: warning: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method boom,
or remove the empty argument list from its definition (Java-defined methods are exempt).
In Scala 3, an unapplied method like this will be eta-expanded into a function. [quickfixable]
Expand Down
20 changes: 20 additions & 0 deletions test/files/pos/t12851c/ScalaNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.math;

/** A marker class for Number types introduced by Scala
*/
public abstract class ScalaNumber extends java.lang.Number {
protected abstract boolean isWhole();
public abstract Object underlying();
}
30 changes: 30 additions & 0 deletions test/files/pos/t12851c/ScalaNumericConversions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//> using option -Werror
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala
package math

/** A slightly more specific conversion trait for classes which
* extend ScalaNumber (which excludes value classes.)
*/
trait ScalaNumericConversions extends ScalaNumber with ScalaNumericAnyConversions {
def underlying: Object
}

/** Conversions which present a consistent conversion interface
* across all the numeric types, suitable for use in value classes.
*/
trait ScalaNumericAnyConversions extends Any {
/** @return `'''true'''` if this number has no decimal component, `'''false'''` otherwise. */
def isWhole: Boolean
}