Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala does not see type method annotations in macros #9755

Open
scabug opened this issue Apr 15, 2016 · 4 comments
Open

Scala does not see type method annotations in macros #9755

scabug opened this issue Apr 15, 2016 · 4 comments

Comments

@scabug
Copy link

scabug commented Apr 15, 2016

I faced pretty strange annotations-related behavior (bug?) with scala macro. Its pretty hard to describe it in one message so I decided to create a sample repo to show it.

https://github.com/akozhemiakin/sandbox-one

In brief, here is the test itself:

package sandbox

import org.scalatest.FunSuite
import sandbox.sub.B

class SandboxSpec extends FunSuite {
  class A[T](el: T)

  test("Test 1") {
    // Here we use simple macro to return number of annotations attached to the "foo" method of the A type arg
    assert(Macro.annosOnFoo(new A(new C)) == 1) // Will succeed
  }

  test("Test 2") {
    // Exactly the same case as above. The only difference: B is not in the same package as A and this test
    assert(Macro.annosOnFoo(new A(new B)) == 1) // Will fail
  }
}

So the problem is, that in the second case scala does not see any annotations attached to the target method.

I did my best to find some similar issue but did not succeed, hope it is not a duplicate.

@scabug
Copy link
Author

scabug commented Apr 15, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9755?orig=1
Reporter: Artyom Kozhemiakin (akozhemiakin)
Affected Versions: 2.11.8, 2.12.0-M3

@scabug
Copy link
Author

scabug commented Apr 15, 2016

@som-snytt said:
In sbt, it fails after clean, then succeeds subsequently (on editing the test file). I see the same behavior using a Java annotation or ClassfileAnnotation, and also after putting the macro and test in different subprojects.

> clean
[success] Total time: 0 s, completed Apr 15, 2016 9:51:14 AM
> ~ test
[info] Updating {file:/home/apm/tmp/sandbox-one/}sandbox...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/apm/tmp/sandbox-one/target/scala-2.11/classes...
[info] Compiling 4 Scala sources and 1 Java source to /home/apm/tmp/sandbox-one/target/scala-2.11/test-classes...
[info] SandboxSpec:
[info] - Test 1
[info] - Test 2 *** FAILED ***
[info]   0 did not equal 1 (SandboxSpec.scala:16)
[info] Run completed in 249 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 1, canceled 0, ignored 0, pending 0
[info] *** 1 TEST FAILED ***
[error] Failed tests:
[error] 	sandbox.SandboxSpec
[error] (test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 6 s, completed Apr 15, 2016 9:51:24 AM
1. Waiting for source changes... (press enter to interrupt)
[info] Compiling 1 Scala source to /home/apm/tmp/sandbox-one/target/scala-2.11/test-classes...
[info] SandboxSpec:
[info] - Test 1
[info] - Test 2
[info] - Dummy
[info] Run completed in 137 milliseconds.
[info] Total number of tests run: 3
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 3, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 2 s, completed Apr 15, 2016 9:51:33 AM

@scabug
Copy link
Author

scabug commented Apr 15, 2016

Artyom Kozhemiakin (akozhemiakin) said:
Yeah, I faced very similar thing while debugging. From time to time it may be compiled successfully without any obvious reason but then fails again.

@scabug
Copy link
Author

scabug commented Sep 29, 2016

@som-snytt said:
Worked for me today by switching the order of the tests. annotations and imports have unusual completion needs. Maybe the import is a clue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants