Skip to content

Commit

Permalink
Enable -Yrepl-class-based to survey test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Dec 10, 2019
1 parent 9ac3039 commit d64af1a
Show file tree
Hide file tree
Showing 21 changed files with 563 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/repl/scala/tools/nsc/interpreter/IMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
// Used in a test case.
def showDirectory() = replOutput.show(out)

lazy val isClassBased: Boolean = settings.Yreplclassbased.value
lazy val isClassBased: Boolean = true
private[interpreter] lazy val useMagicImport: Boolean = true

private[nsc] var printResults = true // whether to print result lines
Expand Down
20 changes: 17 additions & 3 deletions test/files/run/macro-bundle-repl.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ scala> import scala.reflect.macros.blackbox.Context
import scala.reflect.macros.blackbox.Context

scala> class Bar(val c: Context) { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar: Unit = macro Bar.impl
defined class Bar
defined term macro bar: Unit
<console>:12: error: macro definition needs to be enabled
by making the implicit value scala.language.experimental.macros visible.
This can be achieved by adding the import clause 'import scala.language.experimental.macros'
or by setting the compiler option -language:experimental.macros.
See the Scaladoc for value scala.language.experimental.macros for a discussion
why the feature needs to be explicitly enabled.
class Bar(val c: Context) { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar: Unit = macro Bar.impl
^

scala> bar
<console>:14: error: not found: value bar
bar
^

scala> class Foo(val c: Context) { def impl = { import c.universe._; c.Expr[Unit](q"()") } }
defined class Foo

scala> def foo: Unit = macro Foo.impl
defined term macro foo: Unit
<console>:14: error: macro bundles must be static
def foo: Unit = macro Foo.impl
^

scala> foo
<console>:14: error: not found: value foo
foo
^

scala> :quit
32 changes: 28 additions & 4 deletions test/files/run/macro-repl-basic.check
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,39 @@ scala> object Macros {
}; class Macros {
def quux(x: Int): Int = macro Impls.quux
}
defined object Macros
defined class Macros
<console>:14: error: macro definition needs to be enabled
by making the implicit value scala.language.experimental.macros visible.
This can be achieved by adding the import clause 'import scala.language.experimental.macros'
or by setting the compiler option -language:experimental.macros.
See the Scaladoc for value scala.language.experimental.macros for a discussion
why the feature needs to be explicitly enabled.
def foo(x: Int): Int = macro Impls.foo
^
<console>:16: error: macro definition needs to be enabled
by making the implicit value scala.language.experimental.macros visible.
def bar(x: Int): Int = macro Impls.bar
^
<console>:18: error: macro definition needs to be enabled
by making the implicit value scala.language.experimental.macros visible.
def quux(x: Int): Int = macro Impls.quux
^

scala>

scala> import Macros.Shmacros._
import Macros.Shmacros._
<console>:13: error: not found: value Macros
import Macros.Shmacros._
^

scala> println(foo(2) + Macros.bar(2) * new Macros().quux(4))
31
<console>:14: error: not found: value foo
println(foo(2) + Macros.bar(2) * new Macros().quux(4))
^
<console>:14: error: not found: value Macros
println(foo(2) + Macros.bar(2) * new Macros().quux(4))
^
<console>:14: error: not found: type Macros
println(foo(2) + Macros.bar(2) * new Macros().quux(4))
^

scala> :quit
12 changes: 10 additions & 2 deletions test/files/run/macro-repl-dontexpand.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ scala> def bar1(c: scala.reflect.macros.blackbox.Context) = ???
bar1: (c: scala.reflect.macros.blackbox.Context)Nothing

scala> def foo1 = macro bar1
defined term macro foo1: Nothing
<console>:12: error: macro implementation reference has wrong shape. required:
macro [<static object>].<method name>[[<type args>]] or
macro [<macro bundle>].<method name>[[<type args>]]
def foo1 = macro bar1
^

scala> def bar2(c: scala.reflect.macros.whitebox.Context) = ???
bar2: (c: scala.reflect.macros.whitebox.Context)Nothing

scala> def foo2 = macro bar2
defined term macro foo2: Nothing
<console>:12: error: macro implementation reference has wrong shape. required:
macro [<static object>].<method name>[[<type args>]] or
macro [<macro bundle>].<method name>[[<type args>]]
def foo2 = macro bar2
^

scala> :quit
14 changes: 11 additions & 3 deletions test/files/run/macro-system-properties.check
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ scala> object GrabContext {
def impl(c: Context)() = { import c.universe._; System.getProperties.put("lastContext", c); c.Expr[Unit](q"()") }
def grab(): Unit = macro impl
}
defined object GrabContext
<console>:19: error: macro implementation reference has wrong shape. required:
macro [<static object>].<method name>[[<type args>]] or
macro [<macro bundle>].<method name>[[<type args>]]
def grab(): Unit = macro impl
^

scala> object Test { class C(implicit a: Any) { GrabContext.grab } }
defined object Test
<console>:15: error: not found: value GrabContext
object Test { class C(implicit a: Any) { GrabContext.grab } }
^

scala> object Test { class C(implicit a: Any) { GrabContext.grab } }
defined object Test
<console>:15: error: not found: value GrabContext
object Test { class C(implicit a: Any) { GrabContext.grab } }
^

scala> :quit
8 changes: 4 additions & 4 deletions test/files/run/repl-colon-type.check
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ scala> :type lazy val f = 5
Int

scala> :type protected lazy val f = 5
<console>:5: error: lazy value f cannot be accessed in object $iw
<console>:5: error: lazy value f cannot be accessed in INSTANCE.$iw
Access to protected lazy value f not permitted because
enclosing object $eval in package $line13 is not a subclass of
object $iw where target is defined
lazy val $result = f
^
class $iw where target is defined
lazy val $result = INSTANCE.f
^

scala> :type def f = 5
=> Int
Expand Down
8 changes: 4 additions & 4 deletions test/files/run/repl-no-imports-no-predef.check
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,21 @@ scala> 55 ; (x: scala.Int) => x + 1 ; () => ((5))
<console>:12: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
55 ; (x: scala.Int) => x + 1 ;;
^
res30: () => Int = <function0>
res30: () => Int = $Lambda$6544/1050942041@5302ef22

scala>

scala> () => 5
res31: () => Int = <function0>
res31: () => Int = $Lambda$6545/1676295269@33eff142

scala> 55 ; () => 5
<console>:11: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
55 ;;
^
res32: () => Int = <function0>
res32: () => Int = $Lambda$6546/1582681622@1c38b0a0

scala> () => { class X ; new X }
res33: () => AnyRef = <function0>
res33: () => AnyRef = $Lambda$6549/2038305728@428804e0

scala>

Expand Down
8 changes: 4 additions & 4 deletions test/files/run/repl-out-dir.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ repl-out-dir-run.obj
$line2
$eval$.class
$eval.class
$read$$iw$.class
$read$$iw.class
$read$.class
$read.class
$line3
$eval$.class
$eval.class
$read$$iw$.class
$read$$iw$Bippy$.class
$read$$iw$Bippy.class
$read$$iw.class
$read$.class
$read.class
$line4
$eval$.class
$eval.class
$read$$iw$.class
$read$$iw.class
$read$.class
$read.class
$line5
$eval$.class
$eval.class
$read$$iw$.class
$read$$iw.class
$read$.class
$read.class
$repl_$init.class
Expand Down
8 changes: 4 additions & 4 deletions test/files/run/repl-parens.check
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ scala> 55 ; (x: Int) => x + 1 ; () => ((5))
<console>:11: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
55 ; (x: Int) => x + 1 ;;
^
res11: () => Int = <function0>
res11: () => Int = $Lambda$6705/1778997070@17df7cde

scala>

scala> () => 5
res12: () => Int = <function0>
res12: () => Int = $Lambda$6706/75596657@457092e2

scala> 55 ; () => 5
<console>:11: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
55 ;;
^
res13: () => Int = <function0>
res13: () => Int = $Lambda$6707/1795994857@65fa5379

scala> () => { class X ; new X }
res14: () => AnyRef = <function0>
res14: () => AnyRef = $Lambda$6708/863796198@6a98e293

scala>

Expand Down
27 changes: 24 additions & 3 deletions test/files/run/repl-term-macros.check
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,49 @@ scala> def impl1(c: Context) = { import c.universe._; c.Expr[Unit](q"()") }
impl1: (c: scala.reflect.macros.blackbox.Context)c.Expr[Unit]

scala> def foo1: Unit = macro impl1
defined term macro foo1: Unit
<console>:14: error: macro implementation reference has wrong shape. required:
macro [<static object>].<method name>[[<type args>]] or
macro [<macro bundle>].<method name>[[<type args>]]
def foo1: Unit = macro impl1
^

scala> foo1
<console>:14: error: not found: value foo1
foo1
^

scala>

scala> def impl2(c: Context)() = { import c.universe._; c.Expr[Unit](q"()") }
impl2: (c: scala.reflect.macros.blackbox.Context)()c.Expr[Unit]

scala> def foo2(): Unit = macro impl2
defined term macro foo2: ()Unit
<console>:14: error: macro implementation reference has wrong shape. required:
macro [<static object>].<method name>[[<type args>]] or
macro [<macro bundle>].<method name>[[<type args>]]
def foo2(): Unit = macro impl2
^

scala> foo2()
<console>:14: error: not found: value foo2
foo2()
^

scala>

scala> def impl3(c: Context)(x: c.Expr[Int])(y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") }
impl3: (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Int])(y: c.Expr[Int])c.Expr[Unit]

scala> def foo3(x: Int)(y: Int): Unit = macro impl3
defined term macro foo3: (x: Int)(y: Int)Unit
<console>:14: error: macro implementation reference has wrong shape. required:
macro [<static object>].<method name>[[<type args>]] or
macro [<macro bundle>].<method name>[[<type args>]]
def foo3(x: Int)(y: Int): Unit = macro impl3
^

scala> foo3(2)(3)
<console>:14: error: not found: value foo3
foo3(2)(3)
^

scala> :quit

0 comments on commit d64af1a

Please sign in to comment.