Skip to content

Instantly share code, notes, and snippets.

@RainWarrior
Created March 21, 2014 08:35
Show Gist options
  • Save RainWarrior/9682035 to your computer and use it in GitHub Desktop.
Save RainWarrior/9682035 to your computer and use it in GitHub Desktop.
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java:1: package <empty> {
[warn] object JavaTest extends {
[warn] def <init>() = _;
[warn] <static> def main(args: scala.Array[String] = _): Unit = _
[warn] };
[warn] class JavaTest extends _root_.java.lang.Object {
[warn] import JavaTest._;
[warn] def <init>() = _
[warn] }
[warn] } source-/home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java,line-1,offset=0
[warn] public class JavaTest
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java:1: object JavaTest extends {
[warn] def <init>() = _;
[warn] <static> def main(args: scala.Array[String] = _): Unit = _
[warn] } source-/home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java,line-1,offset=13
[warn] public class JavaTest
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java:3: <static> def main(args: scala.Array[String] = _): Unit = _ source-/home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java,line-3,offset=44
[warn] public static void main(String[] args)
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java:3: var args: scala.Array[String] = _ source-/home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java,line-3,offset=58
[warn] public static void main(String[] args)
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java:3: scala.Array[String] source-/home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java,line-3,offset=56
[warn] public static void main(String[] args)
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java:3: String source-/home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java,line-3,offset=49
[warn] public static void main(String[] args)
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java:3: Unit source-/home/rainwarrior/minecraft/sc4/plugin-test/JavaTest.java,line-3,offset=45
[warn] public static void main(String[] args)
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:1: package <empty> {
[warn] object Test extends scala.AnyRef {
[warn] def <init>() = {
[warn] super.<init>();
[warn] ()
[warn] };
[warn] val five = 5;
[warn] val amount = five.$div(0);
[warn] def main(args: Array[String]): scala.Unit = println(amount)
[warn] }
[warn] } source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-1,offset=7
[warn] object Test {
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:1: scala.AnyRef {
[warn] def <init>() = {
[warn] super.<init>();
[warn] ()
[warn] };
[warn] val five = 5;
[warn] val amount = five.$div(0);
[warn] def main(args: Array[String]): scala.Unit = println(amount)
[warn] } source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-1,offset=12
[warn] object Test {
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:7: scala.AnyRef source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-7,offset=112
[warn] }
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:2: val five = 5 source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-2,offset=20
[warn] val five = 5
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:2: 5 source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-2,offset=27
[warn] val five = 5
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:3: val amount = five.$div(0) source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-3,offset=35
[warn] val amount = five / 0
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:3: five.$div(0) source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-3,offset=49
[warn] val amount = five / 0
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:3: five source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-3,offset=44
[warn] val amount = five / 0
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:3: 0 source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-3,offset=51
[warn] val amount = five / 0
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:4: def main(args: Array[String]): scala.Unit = println(amount) source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-4,offset=59
[warn] def main(args: Array[String]) {
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:4: val args: Array[String] = _ source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-4,offset=64
[warn] def main(args: Array[String]) {
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:4: Array[String] source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-4,offset=70
[warn] def main(args: Array[String]) {
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:4: String source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-4,offset=76
[warn] def main(args: Array[String]) {
[warn] ^
[warn] <empty> NoPosition
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:5: println(amount) source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-5,offset=98
[warn] println(amount)
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:5: println source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-5,offset=91
[warn] println(amount)
[warn] ^
[warn] /home/rainwarrior/minecraft/sc4/plugin-test/test.scala:5: amount source-/home/rainwarrior/minecraft/sc4/plugin-test/test.scala,line-5,offset=99
[warn] println(amount)
[warn] ^
[warn] 24 warnings found
package testplugin
import scala.tools.nsc
import nsc.Global
import nsc.Phase
import nsc.plugins.Plugin
import nsc.plugins.PluginComponent
/**
* An example of a simple compiler plugin, which checks for obvious
* cases of division by zero where the denominator in the division
* expression is the constant zero:
*
* {{{
* val x = y / 0
* }}}
*
* For more information on how this plugin is implemented, see
* [[http://www.scala-lang.org/node/140 Writing Scala Compiler Plugins]]
* by Lex Spoon.
*/
class DivByZero(val global: Global) extends Plugin {
val name = "divbyzero"
val description = "checks for division by zero"
val components = List[PluginComponent](new DivByZeroComponent(global))
}
class DivByZeroComponent(val global : Global) extends PluginComponent {
import global._
val runsAfter = List("parser")
override val runsBefore = List("namer")
val phaseName = "divbyzero"
def newPhase(_prev: Phase) = new DivByZeroPhase(_prev)
class DivByZeroPhase(prev: Phase) extends StdPhase(prev) {
override def name = "divbyzero"
def apply(unit: CompilationUnit) {
for(tree <- unit.body) { unit.warning(tree.pos, s"$tree ${tree.pos}") }
/*for ( tree @ Apply(Select(rcvr, nme.DIV), List(Literal(Constant(0)))) <- unit.body;
if rcvr.tpe <:< definitions.IntClass.tpe)
{
unit.error(tree.pos, s"definitely division by zero ${tree.pos}")
}*/
}
}
}
public class JavaTest
{
public static void main(String[] args)
{
System.out.println(args.length);
}
}
object Test {
val five = 5
val amount = five / 0
def main(args: Array[String]) {
println(amount)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment