Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
scala> import scala.tools.nsc._, reporters._; val reporter = new StoreReporter; val settings = new Settings(); settings.processArgumentString("-usejavacp -Ystop-after:refchecks"); val global = new Global(settings, reporter)
import scala.tools.nsc._
import reporters._
reporter: scala.tools.nsc.reporters.StoreReporter = scala.tools.nsc.reporters.StoreReporter@5e18a6a7
settings: scala.tools.nsc.Settings =
Settings {
-d = .
-Ystop-after = List(refchecks)
-usejavacp = true
-encoding = UTF-8
}
global: scala.tools.nsc.Global = scala.tools.nsc.Global@505e483f
scala> {val run = new global.Run; run.compileSources(global.newSourceFile("class X { val x: Int = 42 }") :: Nil); println(reporter.infos); println(run.units.toList.head.body); reporter.reset()}
Set()
package <empty> {
class X extends scala.AnyRef {
def <init>(): X = {
X.super.<init>();
()
};
private[this] val x: Int = 42;
<stable> <accessor> def x: Int = X.this.x
}
}
scala> {val run = new global.Run; run.compileSources(global.newSourceFile("class X { val x: Int = this }") :: Nil); println(reporter.infos); println(run.units.toList.head.body); reporter.reset()}
Set(pos: source-<console>,line-1,offset=23 type mismatch;
found : X
required: Int ERROR)
package <empty> {
class X extends scala.AnyRef {
def <init>(): X = {
X.super.<init>();
()
};
private[this] val x: Int = this;
<stable> <accessor> def x: Int = X.this.x
}
}
scala> {val run = new global.Run; run.compileSources(global.newSourceFile("class X { val x: Int = 42 }") :: Nil); println(reporter.infos); println(global.show(run.units.toList.head.body, printTypes = true)); reporter.reset()}
Set()
package <empty>{<empty>.type} {
class X extends scala.AnyRef {
def <init>(): X = {
X.super.<init>{()Object}(){Object};
(){Unit}
}{Unit};
private[this] val x: Int = 42{Int(42)};
<stable> <accessor> def x: Int = X.this.x{Int}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.