Skip to content

Instantly share code, notes, and snippets.

@retronym
Last active August 29, 2015 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/3f8b68abe7817a722a8a to your computer and use it in GitHub Desktop.
Save retronym/3f8b68abe7817a722a8a to your computer and use it in GitHub Desktop.
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