diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-04 22:49:16 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-04 22:49:16 -0700 |
commit | 6e1243ba2eb2acf3f1fb2b397c0c22ea0e746f1a (patch) | |
tree | 95f5165a2a73d6c2159ea5f2e6cc012596bc3b84 /core/src/test/scala/forge | |
parent | 57087e0f2b91d7b906ddda6a7078fa36fdabbbcb (diff) | |
download | mill-6e1243ba2eb2acf3f1fb2b397c0c22ea0e746f1a.tar.gz mill-6e1243ba2eb2acf3f1fb2b397c0c22ea0e746f1a.tar.bz2 mill-6e1243ba2eb2acf3f1fb2b397c0c22ea0e746f1a.zip |
First pass at providing good compile errors to invalid uses of the `T{...}` macro: we should only allow you to `Target#apply()` on expressions whose values come from outside the `T{...}` block
Diffstat (limited to 'core/src/test/scala/forge')
-rw-r--r-- | core/src/test/scala/forge/CacherTests.scala | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/core/src/test/scala/forge/CacherTests.scala b/core/src/test/scala/forge/CacherTests.scala index de8265bd..d77287ac 100644 --- a/core/src/test/scala/forge/CacherTests.scala +++ b/core/src/test/scala/forge/CacherTests.scala @@ -50,8 +50,39 @@ object CacherTests extends TestSuite{ val expectedMsg = "T{} members defined in a Cacher class/trait/object body must be defs" - val err1 = compileError("object Foo extends Target.Cacher{ val x = T{1} }") - assert(err1.msg == expectedMsg) + val err = compileError("object Foo extends Target.Cacher{ val x = T{1} }") + assert(err.msg == expectedMsg) + } + 'badTmacro - { + // Make sure we can reference values from outside the T{...} block as part + // of our `Target#apply()` calls, but we cannot reference any values that + // come from inside the T{...} block + 'pos - { + val a = T{ 1 } + val arr = Array(a) + val b = { + val c = 0 + T{ + arr(c)() + } + } + } + 'neg - { + + val expectedMsg = + "Target#apply() call cannot use `value n` defined within the T{...} block" + val err = compileError("""{ + val a = T{ 1 } + val arr = Array(a) + val b = { + T{ + val n = 0 + arr(n)() + } + } + }""") + assert(err.msg == expectedMsg) + } } } } |