I have a strange IDE error, but the code compiles and runs. How can I fix the problem? A code example and a screenshot of the issue are attached.

Answered

I have a strange IDE error, but the code compiles and runs. How can I fix the problem? A code example and a screenshot of the issue are attached.

--------------------

Type mismatch.
Required:
ZServerEndpoint [Any,Any]
Found:
ZServerEndpoint[Any,Any]

--------------------

import zio._
import sttp.tapir.ztapir._
import sttp.tapir.server.ziohttp.ZioHttpInterpreter
import zio.http.{Response, Routes, Server}
object Main extends ZIOAppDefault {
 case class Pet(species: String, url: String)
   def authLogic(token: String): ZIO[Any, String, String] = {
     if (token != "secret")
       ZIO.fail("user not login")
     else ZIO.succeed(token)
   }
   val authEndpoint: ZPartialServerEndpoint[Any, String, String, Unit, String, Unit, Any] =
     endpoint
       .securityIn(auth.bearer[String]())
       .errorOut(stringBody)
       .zServerSecurityLogic(authLogic)
 val secureHelloWorldEndpoint: ZServerEndpoint[Any, Any] = authEndpoint
   .get
   .in("hello")
   .in(query[String]("salutation"))
   .out(stringBody)
   .serverLogic { token => salutation =>
     ZIO.succeed(s"$salutation, authenticated with token: $token!")
   }
 val routes: Routes[Any, Response] = ZioHttpInterpreter().toHttp(secureHelloWorldEndpoint)
 override def run: URIO[Any, ExitCode] =
   Server
     .serve(routes)
     .provide(
       ZLayer.succeed(Server.Config.default.port(8080)),
       Server.live
     )
     .exitCode
}
0
6 comments

I have noticed these as well. These are probably Scala 3 related issues. Sometimes when I delete the line and re-type, it goes way. Sometimes these go away after successful completion. YMMV.

Scala 3 support in IntelliJ is not full proof yet.

0

After I updated the Scala plugin to 2024.2.29 the IDE is showing nonsensical errors. 

I'm in a project that's a mix of Scala 2.12 and Java 8 code and the IDE shows errors like `Identifier expected` and `';' expected` in Java code. (The code is correct and builds fine with gradle)

So it looks like the issue isn't just confined to Scala 3.

0

Erik Forkalsrud Do I understand it right that you don't have any Scala 3 code in your code base?
Any change you have enabled compiler-based highlighting in your code?
 (it shouldn't be enabled by default for Scala 2)

0

Correct, it's Scala 2.12 and Java 8, and I'm pretty sure I never enabled any compiler based highlighting.

That said, I tried some more updates yesterday, and now I'm on IDEA 2024.3 and the Scala plugin is 2024.3.18. I haven't seen the issue after those updates. Another thing I should point out is that our code mostly has Scala classes reference Java classes, but a couple of instances where Java classes reference Scala code. The result of that bidirectional dependency is that the Java and Scala code has to be compiled at the same time.  So our gradle build had:

sourceSets {
   main {
       scala { srcDirs = ['src/main/scala', 'src/main/java'] }
       java { srcDirs = [] }
   }
}

I refactored this so that non of the Java classes reference Scala code, which means the Java code can be compiled separately. Our  gradle config can then be:

sourceSets {
   main {
       scala { srcDirs = ['src/main/scala'] }
       java { srcDirs = ['src/main/java'] }
   }
}

Sadly, I'm not sure which of these changes made the difference, but I haven't been able to reproduce the issue.

0

Erik Forkalsrud I hope you won't see the error again and it's resolved once and for all.
But if you ever see it again, please create an issue https://youtrack.jetbrains.com/newIssue?project=SCL
You case seems to be different from the original post description. 

0

Please sign in to leave a comment.