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

Make the method ## have no parameter list (instead of a single empty one) #8814

Merged
merged 1 commit into from Apr 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library-aux/scala/Any.scala
Expand Up @@ -108,7 +108,7 @@ abstract class Any {
*
* @return a hash value consistent with ==
*/
final def ##(): Int = sys.error("##")
final def ## : Int = sys.error("##")

/** Test whether the dynamic type of the receiver object is `T0`.
*
Expand Down
12 changes: 7 additions & 5 deletions src/reflect/scala/reflect/internal/Definitions.scala
Expand Up @@ -38,14 +38,16 @@ trait Definitions extends api.StandardDefinitions {
val clazz = owner.newClassSymbol(name, NoPosition, flags)
clazz.setInfoAndEnter(ClassInfoType(parents, newScope, clazz)).markAllCompleted
}
private def newMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long): MethodSymbol = {
private def newMethod(owner: Symbol, name: TermName, formals: List[Type], mkMeth: List[TermSymbol] => Type, flags: Long): MethodSymbol = {
val msym = owner.newMethod(name.encode, NoPosition, flags)
val params = msym.newSyntheticValueParams(formals)
val info = MethodType(params, restpe)
val info = mkMeth(params)
msym.setInfo(info).markAllCompleted
}
private def enterNewMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long = 0L): MethodSymbol =
owner.info.decls enter newMethod(owner, name, formals, restpe, flags)
owner.info.decls enter newMethod(owner, name, formals, MethodType(_, restpe), flags)
private def enterNewNullaryMethod(owner: Symbol, name: TermName, restpe: Type, flags: Long): MethodSymbol =
owner.info.decls enter newMethod(owner, name, Nil, _ => NullaryMethodType(restpe), flags)

// the scala value classes
trait ValueClassDefinitions {
Expand Down Expand Up @@ -1108,7 +1110,7 @@ trait Definitions extends api.StandardDefinitions {
lazy val Any_equals = enterNewMethod(AnyClass, nme.equals_, AnyTpe :: Nil, BooleanTpe)
lazy val Any_hashCode = enterNewMethod(AnyClass, nme.hashCode_, Nil, IntTpe)
lazy val Any_toString = enterNewMethod(AnyClass, nme.toString_, Nil, StringTpe)
lazy val Any_## = enterNewMethod(AnyClass, nme.HASHHASH, Nil, IntTpe, FINAL)
lazy val Any_## = enterNewNullaryMethod(AnyClass, nme.HASHHASH, IntTpe, FINAL)

// Any_getClass requires special handling. The return type is determined on
// a per-call-site basis as if the function being called were actually:
Expand Down Expand Up @@ -1206,7 +1208,7 @@ trait Definitions extends api.StandardDefinitions {
}

// members of class java.lang.{ Object, String }
lazy val Object_## = enterNewMethod(ObjectClass, nme.HASHHASH, Nil, IntTpe, FINAL)
lazy val Object_## = enterNewNullaryMethod(ObjectClass, nme.HASHHASH, IntTpe, FINAL)
lazy val Object_== = enterNewMethod(ObjectClass, nme.EQ, AnyTpe :: Nil, BooleanTpe, FINAL)
lazy val Object_!= = enterNewMethod(ObjectClass, nme.NE, AnyTpe :: Nil, BooleanTpe, FINAL)
lazy val Object_eq = enterNewMethod(ObjectClass, nme.eq, AnyRefTpe :: Nil, BooleanTpe, FINAL)
Expand Down
10 changes: 10 additions & 0 deletions test/files/neg/auto-application.check
@@ -0,0 +1,10 @@
auto-application.scala:2: error: Int does not take parameters
("": Any).##()
^
auto-application.scala:3: error: Int does not take parameters
("": AnyRef).##()
^
auto-application.scala:4: error: Int does not take parameters
("": Object).##()
^
3 errors
5 changes: 5 additions & 0 deletions test/files/neg/auto-application.scala
@@ -0,0 +1,5 @@
class Test {
("": Any).##()
("": AnyRef).##()
("": Object).##()
}
1 change: 0 additions & 1 deletion test/files/pos/auto-application.scala
Expand Up @@ -8,7 +8,6 @@ class Test {
def a5(xs: List[String]): Class[_] = xs.getClass
def a6(xs: List[String]): Class[_] = xs.getClass()
def a7(xs: List[String]): Int = xs.##
def a8(xs: List[String]): Int = xs.##()
def a9(x: Address): String = x.toString
def a10(x: Address): String = x.toString()
def a11(x: A): String = x.toString
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/callcc-interpreter.check
Expand Up @@ -38,7 +38,7 @@ def toString(): String
def unitM[A](a: A): callccInterpreter.M[A]
def →[B](y: B): (callccInterpreter.type, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/completion-implicit-chained.check
Expand Up @@ -11,7 +11,7 @@ def hashCode(): Int
def map(x: Int => Int)(implicit a: DummyImplicit): test.O.type
def toString(): String
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/ide-bug-1000349.check
Expand Up @@ -17,7 +17,7 @@ def hashCode(): Int
def toString(): String
def →[B](y: B): (Foo, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
6 changes: 3 additions & 3 deletions test/files/presentation/ide-bug-1000475.check
Expand Up @@ -18,7 +18,7 @@ def hashCode(): Int
def toString(): String
def →[B](y: B): (Object, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down Expand Up @@ -50,7 +50,7 @@ def hashCode(): Int
def toString(): String
def →[B](y: B): (Object, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down Expand Up @@ -82,7 +82,7 @@ def hashCode(): Int
def toString(): String
def →[B](y: B): (Object, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/ide-bug-1000531.check
Expand Up @@ -20,7 +20,7 @@ def next: T
def toString(): String
def →[B](y: B): (other.TestIterator[Nothing], B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/implicit-member.check
Expand Up @@ -17,7 +17,7 @@ def toString(): String
def →[B](y: B): (Implicit.type, B)
final class AppliedImplicit[A] extends AnyRef
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/infix-completion.check
Expand Up @@ -172,7 +172,7 @@ def |(x: Long): Long
def |(x: Short): Int
def →[B](y: B): (Int, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/infix-completion2.check
Expand Up @@ -172,7 +172,7 @@ def |(x: Long): Long
def |(x: Short): Int
def →[B](y: B): (Int, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
4 changes: 2 additions & 2 deletions test/files/presentation/ping-pong.check
Expand Up @@ -19,7 +19,7 @@ def hashCode(): Int
def poke(): Unit
def →[B](y: B): (Pong, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down Expand Up @@ -55,7 +55,7 @@ def name: String
def poke: Unit
def →[B](y: B): (Ping, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/t5708.check
Expand Up @@ -22,7 +22,7 @@ def hashCode(): Int
def toString(): String
def →[B](y: B): (test.Compat.type, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
10 changes: 5 additions & 5 deletions test/files/presentation/visibility.check
Expand Up @@ -19,7 +19,7 @@ def someTests(other: accessibility.Foo): Unit
def toString(): String
def →[B](y: B): (accessibility.Foo, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down Expand Up @@ -56,7 +56,7 @@ def someTests(other: accessibility.Foo): Unit
def toString(): String
def →[B](y: B): (accessibility.Foo, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down Expand Up @@ -95,7 +95,7 @@ def someTests: Unit
def toString(): String
def →[B](y: B): (accessibility.AccessibilityChecks, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down Expand Up @@ -136,7 +136,7 @@ def someTests(other: accessibility.Foo): Unit
def toString(): String
def →[B](y: B): (accessibility.Foo, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down Expand Up @@ -175,7 +175,7 @@ def someTests(other: accessibility.Foo): Unit
def toString(): String
def →[B](y: B): (accessibility.Foo, B)
final def !=(x$1: Any): Boolean
final def ##(): Int
final def ## : Int
final def ==(x$1: Any): Boolean
final def asInstanceOf[T0]: T0
final def eq(x$1: AnyRef): Boolean
Expand Down
17 changes: 10 additions & 7 deletions test/files/run/compiler-asSeenFrom.scala
Expand Up @@ -148,10 +148,13 @@ package ll {

def pretty(xs: List[_]) = if (xs.isEmpty) "" else xs.mkString("\n ", "\n ", "\n")

def signaturesIn(info: Type): List[String] = (
info.members.toList
filterNot (s => s.isType || s.owner == ObjectClass || s.owner == AnyClass || s.isConstructor)
map (_.defString)
def signaturesIn(sym: Symbol): List[String] = (
if (sym.owner == ObjectClass || sym.owner == AnyClass) Nil
lrytz marked this conversation as resolved.
Show resolved Hide resolved
else {
sym.tpe.members.toList
.filterNot(s => s.isType || s.owner == ObjectClass || s.owner == AnyClass || s.isConstructor)
.map(_.defString)
}
)

def check(source: String, unit: global.CompilationUnit) = {
Expand All @@ -161,10 +164,10 @@ package ll {
val typeArgs = List[Type](IntClass.tpe, ListClass[Int]) ++ tparams.map(_.tpe)
permute(typeArgs) foreach println
}
for (x <- classes ++ terms) {
afterEachPhase(signaturesIn(x.tpe)) collect {
for (sym <- classes ++ terms) {
afterEachPhase(signaturesIn(sym)) collect {
case (ph, sigs) if sigs.nonEmpty =>
println(sigs.mkString(x.toString + " { // after " + ph + "\n ", "\n ", "\n}\n"))
println(sigs.mkString(s"$sym { // after $ph\n ", "\n ", "\n}\n"))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/files/run/reflection-magicsymbols-invoke.check
Expand Up @@ -3,7 +3,7 @@ Any
it's important to print the list of Any's members
if some of them change (possibly, adding and/or removing magic symbols), we must update this test
method !=: (x$1: Any): Boolean
method ##: (): Int
method ##: Int
method ==: (x$1: Any): Boolean
method asInstanceOf: [T0]T0
method equals: (x$1: Any): Boolean
Expand Down Expand Up @@ -36,7 +36,7 @@ it's important to print the list of AnyRef's members
if some of them change (possibly, adding and/or removing magic symbols), we must update this test
constructor Object: (): Object
method !=: (x$1: Any): Boolean
method ##: (): Int
method ##: Int
method $asInstanceOf: [T0](): T0
method $isInstanceOf: [T0](): Boolean
method ==: (x$1: Any): Boolean
Expand Down Expand Up @@ -81,7 +81,7 @@ it's important to print the list of Array's members
if some of them change (possibly, adding and/or removing magic symbols), we must update this test
constructor Array: (_length: Int): Array[T]
method !=: (x$1: Any): Boolean
method ##: (): Int
method ##: Int
method $asInstanceOf: [T0](): T0
method $isInstanceOf: [T0](): Boolean
method ==: (x$1: Any): Boolean
Expand Down
18 changes: 9 additions & 9 deletions test/files/run/reflection-valueclasses-magic.check
Expand Up @@ -11,7 +11,7 @@ method !=: (x: Float): Boolean
method !=: (x: Int): Boolean
method !=: (x: Long): Boolean
method !=: (x: Short): Boolean
method ##: (): Int
method ##: Int
method %: (x: Byte): Int
method %: (x: Char): Int
method %: (x: Double): Double
Expand Down Expand Up @@ -219,7 +219,7 @@ method !=: (x: Float): Boolean
method !=: (x: Int): Boolean
method !=: (x: Long): Boolean
method !=: (x: Short): Boolean
method ##: (): Int
method ##: Int
method %: (x: Byte): Int
method %: (x: Char): Int
method %: (x: Double): Double
Expand Down Expand Up @@ -427,7 +427,7 @@ method !=: (x: Float): Boolean
method !=: (x: Int): Boolean
method !=: (x: Long): Boolean
method !=: (x: Short): Boolean
method ##: (): Int
method ##: Int
method %: (x: Byte): Int
method %: (x: Char): Int
method %: (x: Double): Double
Expand Down Expand Up @@ -635,7 +635,7 @@ method !=: (x: Float): Boolean
method !=: (x: Int): Boolean
method !=: (x: Long): Boolean
method !=: (x: Short): Boolean
method ##: (): Int
method ##: Int
method %: (x: Byte): Int
method %: (x: Char): Int
method %: (x: Double): Double
Expand Down Expand Up @@ -843,7 +843,7 @@ method !=: (x: Float): Boolean
method !=: (x: Int): Boolean
method !=: (x: Long): Boolean
method !=: (x: Short): Boolean
method ##: (): Int
method ##: Int
method %: (x: Byte): Long
method %: (x: Char): Long
method %: (x: Double): Double
Expand Down Expand Up @@ -1051,7 +1051,7 @@ method !=: (x: Float): Boolean
method !=: (x: Int): Boolean
method !=: (x: Long): Boolean
method !=: (x: Short): Boolean
method ##: (): Int
method ##: Int
method %: (x: Byte): Float
method %: (x: Char): Float
method %: (x: Double): Double
Expand Down Expand Up @@ -1237,7 +1237,7 @@ method !=: (x: Float): Boolean
method !=: (x: Int): Boolean
method !=: (x: Long): Boolean
method !=: (x: Short): Boolean
method ##: (): Int
method ##: Int
method %: (x: Byte): Double
method %: (x: Char): Double
method %: (x: Double): Double
Expand Down Expand Up @@ -1417,7 +1417,7 @@ if some of them change (possibly, adding and/or removing magic symbols), we must
constructor Boolean: (): Boolean
method !=: (x$1: Any): Boolean
method !=: (x: Boolean): Boolean
method ##: (): Int
method ##: Int
method &&: (x: Boolean): Boolean
method &: (x: Boolean): Boolean
method ==: (x$1: Any): Boolean
Expand Down Expand Up @@ -1446,7 +1446,7 @@ it's important to print the list of Byte's members
if some of them change (possibly, adding and/or removing magic symbols), we must update this test
constructor Unit: (): Unit
method !=: (x$1: Any): Boolean
method ##: (): Int
method ##: Int
method ==: (x$1: Any): Boolean
method asInstanceOf: [T0]T0
method equals: (x$1: Any): Boolean
Expand Down