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

Partial support for super accessors (fix #100) #326

Merged
merged 1 commit into from
Jan 19, 2019
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
15 changes: 15 additions & 0 deletions examples/dependencies/src/main/scala/100.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ticket100

trait T1 {
def x: Int = ???
}

trait T2 extends T1 {
private def super$x(self: T1): Int = ???
def y: Int = super.x
}

trait HasRemoteInfo extends Exception {
private def super$getMessage(self: java.lang.Throwable)(): String = ???
def exceptionMessage(): String = super.getMessage()
}
5 changes: 5 additions & 0 deletions examples/semantic/src/main/scala/100.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ticket100

class C extends T2

class E extends Exception with HasRemoteInfo
39 changes: 33 additions & 6 deletions rsc/src/main/scala/rsc/scalasig/Pickle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ class Pickle private (settings: Settings, mtab: Mtab, sroot1: String, sroot2: St
}
entries.getOrElseUpdate(key) {
val name = {
ssym.name match {
case name: TermName => emitName(name)
case TypeName(v) if isModule => emitName(TermName(v))
case name: TypeName => emitName(name)
// FIXME: https://github.com/twitter/rsc/issues/100
if (ssym.desc.isMethod) {
emitName(TermName(ssym.desc.value))
} else {
ssym.name match {
case name: TermName => emitName(name)
case TypeName(v) if isModule => emitName(TermName(v))
case name: TypeName => emitName(name)
}
}
}
val owner = {
Expand Down Expand Up @@ -114,7 +119,7 @@ class Pickle private (settings: Settings, mtab: Mtab, sroot1: String, sroot2: St
ClassSymbol(name, owner, flags, within, info, thisType)
} else if (ssym.isDef || ssym.isParam || ssym.isField) {
// FIXME: https://github.com/twitter/rsc/issues/100
val alias = None
val alias = ssym.salias.map(emitSym(_, RefMode))
ValSymbol(name, owner, flags, within, info, alias)
} else {
val sdefault = s.SymbolInformation(symbol = ssym)
Expand Down Expand Up @@ -504,6 +509,9 @@ class Pickle private (settings: Settings, mtab: Mtab, sroot1: String, sroot2: St
def isAccessor: Boolean = {
sinfo.isMethod && (sinfo.isVal || sinfo.isVar)
}
def isSuperAccessor: Boolean = {
sinfo.displayName.startsWith("super$")
}
def isGetter: Boolean = {
ssym.isAccessor && !ssym.desc.value.endsWith("_=")
}
Expand Down Expand Up @@ -631,6 +639,9 @@ class Pickle private (settings: Settings, mtab: Mtab, sroot1: String, sroot2: St
def isExistential: Boolean = {
history.isExistential(ssym)
}
def isArtifact: Boolean = {
sinfo.displayName.startsWith("super$")
}
def isJavaAnnotation: Boolean = {
sinfo.signature match {
case s.ClassSignature(_, parents, _, _) =>
Expand Down Expand Up @@ -700,9 +711,11 @@ class Pickle private (settings: Settings, mtab: Mtab, sroot1: String, sroot2: St
if (ssym.isDefaultParam) result |= DEFAULTPARAM
if (ssym.isTrait) result |= TRAIT
if (ssym.isAccessor) result |= ACCESSOR
if (ssym.isSuperAccessor) result |= SUPERACCESSOR
if (ssym.isParamAccessor) result |= PARAMACCESSOR
if (ssym.isLazy) result |= LAZY
if (ssym.isExistential) result |= EXISTENTIAL
if (ssym.isArtifact) result |= ARTIFACT
if (ssym.isJavaAnnotation) result |= JAVA_ANNOTATION
result
}
Expand All @@ -725,7 +738,9 @@ class Pickle private (settings: Settings, mtab: Mtab, sroot1: String, sroot2: St
else ClassSig(sparents.toList, ssym)
}
maybePolySig(stparamSyms, ssig)
case s.MethodSignature(stparamSyms, sparamSymss, sretopt) =>
case s.MethodSignature(stparamSyms, sparamSymss0, sretopt) =>
// FIXME: https://github.com/twitter/rsc/issues/100
val sparamSymss = if (isSuperAccessor) sparamSymss0.tail else sparamSymss0
val sret = if (ssym.isCtor) ssym.owner.stpe else sretopt
val ssig = {
if (sparamSymss.isEmpty) {
Expand Down Expand Up @@ -806,6 +821,18 @@ class Pickle private (settings: Settings, mtab: Mtab, sroot1: String, sroot2: St
}
s.TypeRef(s.NoType, ssym, stargs)
}
def salias: Option[String] = {
if (isSuperAccessor) {
// FIXME: https://github.com/twitter/rsc/issues/100
val s.MethodSignature(_, List(sselfParams, _*), _) = sinfo.signature
val List(sselfParam) = sselfParams.symbols
val s.ValueSignature(s.TypeRef(_, sparent, _)) = mtab.get(sselfParam).get.signature
val svalue = ssym.desc.value.stripPrefix("super$")
Some(Symbols.Global(sparent, d.Method(svalue, "()")))
} else {
None
}
}
}

private implicit class ValueOps(value: String) {
Expand Down