-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Symbol.newClass does not support class parameters #21739
Comments
Not sure whether I should create a new issue or ask here. I think this issue is closely related to mine. I have an issue ScalaMock/ScalaMock#191 created long time ago. And to fix it I need possibility to annotate a class created with Symbol.newClass. I didn't find a way to do it currently. |
@goshacodes I've now added the ability to add annotations to classes in #21880. I will probably end up changing the title/explanations of the PR before review from the compiler team members, but in terms of the code/functionality itself - I consider it done, and if nothing bad comes up, and after merging with @experimental for 3.7 I would like to stabilize it in 3.8/3.9. As a power user of |
Looks like everything is covered, has nothing special in mind currently, thank you!
|
Found one test case recently, which looks strange: class MyClass
class MyTycon[T]
class WithGeneric[T, B[_]](b: B[T], t: T)
mock[WithGeneric[MyClass, Option]] // not compiles
mock[WithGeneric[MyClass, MyTycon]] // not compiles
Error is: [error] 57 | mock[WithGeneric[MyClass, Option]]
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | Found: Option[MyClass]
[error] | Required: Option[MyClass]
[error] |
----
[error] | Explanation (enabled by `-explain`)
[error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error] |
[error] | Tree: org.scalamock.util.Defaultable.default[Option[Int]].default.asInstanceOf[
[error] | Option[Int]]
[error] | I tried to show that
[error] | Option[Int]
[error] | conforms to
[error] | Option[Int]
[error] | but none of the attempts shown below succeeded:
[error] |
[error] | ==> Option[Int] <: Option[Int]
[error] | ==> Any <: Option[Int] = false
[error] |
[error] | The tests were made under a constraint with:
[error] | uninstantiated variables: X0
[error] | constrained types: [X0]: X0
[error] | bounds:
[error] | X0
[error] | ordering:
[error] | co-deps:
[error] | contra-deps: Now I'm replacing all generic types with applied types by hand and casting nulls to that type - will be nice to check if this can be done now with Symbol.newClass. This is exactly what I do, maybe I'm just doing something wrong: UPDATE: found correct solution
|
Compiler version
3.5.1
Minimized example
Mill's Cross Modules are implemented with a macro that generates a class, and a factory function that creates a new instance of the class given some context.
The new class has to be generated via Macro, not quotes and splices, because the Specific cross module trait is not known statically.
The problem is that there is no way via
Symbol.newClass
to add the necessary(ctx: Context)
parameter to the generated classC
Expectation
Allow to customise the parameters of the class, even if its just single term parameter list, I think generic is less needed because the macro can specialise the types.
The text was updated successfully, but these errors were encountered: