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

@accessible macro highlights as error but runs in tests #429

Closed
Ellzord opened this issue Apr 18, 2023 · 9 comments · Fixed by #433
Closed

@accessible macro highlights as error but runs in tests #429

Ellzord opened this issue Apr 18, 2023 · 9 comments · Fixed by #433
Assignees

Comments

@Ellzord
Copy link

Ellzord commented Apr 18, 2023

          @myazinn I've got the latest version of intellij and I can see this has not been fixed.

image

In this code the first error is the method is overloaded (Position and Chunk[Position]), the second error it doesn't like the new type and considers it to be Nothing, and in the hover you can see it thinks the return type is Chunk[Any].

image

IntelliJ IDEA 2023.1 (Community Edition)
Build #IC-231.8109.175, built on March 28, 2023
Runtime version: 17.0.6+10-b829.5 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Registry:
    scala.erase.compiler.process.jdk.once=false

Non-Bundled Plugins:
    org.intellij.scala (2023.1.16)
    zio.intellij.zio-intellij (2023.1.24.0)

Kotlin: 231-1.8.20-IJ8109.175

I'm unable to reopen the issue myself, can you do this for me? If it helps this is in src/test while a previous example it was in src/main.

Originally posted by @Ellzord in #366 (comment)

@Ellzord
Copy link
Author

Ellzord commented Apr 18, 2023

image
image
image

@hmemcpy
Copy link
Collaborator

hmemcpy commented Apr 18, 2023

Thanks so much for the reports! I'll try looking into this as well, though I admit the macro stuff is black magic to me!

But a question: is Postgres.tenants (and its implicit context, etc) something in your code base, or is it a part of some library?

@Ellzord
Copy link
Author

Ellzord commented Apr 19, 2023

@hmemcpy it's part of my code base. Playing around with aspects to make my postgres tests easier to write/reason about

@Ellzord
Copy link
Author

Ellzord commented Apr 20, 2023

It looks like I get the same issues in src/main too. Is there anything else I can add to help diagnosing this?

@myazinn
Copy link
Collaborator

myazinn commented Apr 21, 2023

@Ellzord I'll take a look today or tomorrow and will come back to you

@myazinn
Copy link
Collaborator

myazinn commented Apr 21, 2023

I've tried to make my code as close as possible to yours but it still works fine 🤔

import zio._
import zio.macros.accessible
import zio.prelude.Newtype

object model {
  object PositionId extends Newtype[Int]
  type PositionId = PositionId.Type

  object EventId extends Newtype[Int]
  type EventId = EventId.Type

  final case class Context(value: Int)
  final case class Position(value: Int)
}

import model._

@accessible
trait Repository {
  def save(Position: Position)(implicit context: Context): UIO[PositionId]
  def save(Positions: Chunk[Position])(implicit context: Context): UIO[Chunk[PositionId]]
  def findByEventId(eventId: EventId)(implicit context: Context): UIO[Chunk[Position]]
}

object Repository {
  val live = ???
}

object ZIO2 {
  implicit val context: Context = Context(1)

  for {
    _ <- Repository.save(Position(1))
    _ <- Repository.save(Chunk(Position(1)))
    _ <- Repository.findByEventId(EventId(1))
  } yield ()

}

Could you please check if the code above is highlighted? If not, it'll be really great if you could simplify and share your code in scastie, because I'm out of ideas on how to reproduce it

@Ellzord
Copy link
Author

Ellzord commented Apr 24, 2023

GitHubBug.zip

@myazinn I've made an example project that shows the problem. It turns out it's related to having different modules. When I try your example in one module it all works fine but if I split it up I get the errors.

I've attached the project in a zip. Is that okay?

@myazinn
Copy link
Collaborator

myazinn commented Apr 25, 2023

That's awesome, thank you! I'll take a look today

@myazinn
Copy link
Collaborator

myazinn commented Apr 25, 2023

@Ellzord yes, now I can see errors
Turns out it's not related to newtypes nor different modules. It's happenning because model case classes are defined within package object. Thanks again for the report! I'll try fixing it soon.

Also, just in case here's a minimized code snippet that reproduces the issue

// separate package object
package bug

package object plugin {
  final case class UserId(id: Int)
}

// another file
package bug.plugin

import zio.UIO
import zio.macros.accessible

@accessible
trait Repo {
  def find(id: UserId): UIO[Unit]
}

object Test extends App {
  println(Repo.find(UserId(1)))
}

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

Successfully merging a pull request may close this issue.

3 participants