Closed cjdxhjj closed 1 year ago
It this problem only visible in the InteliJ or is it only present in normal compilation using gradle/sbt/mill or other build tool? InteliJ has it's own presentation compiler, which might be bugged - might show errors for code which would compile correctly when using actual Scala compiler.
If possible try to compile it using the gradle cli to check if it's just the InteliJ issue. Also, make sure to use the latest version of InteliJ + Scala Plugin as it follows rapid development cycle and typically it's recommended to stay on their bleeding edge versions.
i'm using gradle 8.3, when i use the gradle cli, it report the same error i'm wanted to upgrade from scala 2.13.11 to 3.3.1, but it alway report that error,
the issure appear half a year, i have tried scala 3.0, 3.1,3.2, jdk 11, jdk 17, zio 1.16, zio 2, i hava no idea to slove that problem, the error may cause by other mistake, but the error report is error
the project work fine on scala 2.13
my idea is 2023.2.2 and scala plugin is 2023.2.23
@cjdxhjj is it possible for you to minimalize it?
@He-Pin yes, i will try to provider an demo, but i'm not sure i could provider it
@He-Pin i can't provider an minimalize demo to repeat that complie error, i guess some other thing went wrong, but the compile report the wrong error scala3test.zip
@WojciechMazur there is any suggest, the project is write by scala 2.13 for three years age, i have upgrade the zio to 2.17, when i upgrade scala from 2 to 3, the error appear.
@cjdxhjj It would be better you have a simple code to demo this, you can post it with text block,better with scala-cli.
你把这个问题搞个小文件复现下,这样大家都好看。比如 scala ...
这样的代码块儿。你现在这个好多自己公司的项目中的类,别个怎么复现呢.
@cjdxhjj Thank you for publishing the code, but it also is working fine on my machine. I really can't tell what might be happening here without the working reproducer leading to compilation error. I doesn't look like issue with the Scala typer, unless there is happening something very strange. You can try to check if there is no imports/package definitions that might shadow the scala.Predef.Array
in some way or you can try to use this type directly in the failing method just to be sure.
@WojciechMazur the demo work fine, but my project build error, the error report point out the code error look like correct
@He-Pin @WojciechMazur i have copy my project and delete some module, the error report again
@cjdxhjj your repo has about 1000 lines of Scala in it. nearly any compiler issue can be demonstrated in about 5–20 lines of code. it's very rare for a minimal reproduction to require 50, let alone 1000
for guidance on what constitutes a minimal reproduction of a bug, see https://stackoverflow.com/help/minimal-reproducible-example
@SethTisue i will try to reduce some code, but i can't figure out what code cause the problem,
@SethTisue , @WojciechMazur, @He-Pin ,after delete some unused class.
What happened here is the implicit conversion, in this case it's PreDef.futureWrapper
The following code:
import com.example.domain.shared.PreDef.*
class Foo {
def addBrandBatch2(brandList: Array[CreateBrandCommand]): ActionListResult[Brand] = {
brandList.map(x =>x.orgId)
???
}
}
is being converted to
class Foo() extends Object() {
def addBrandBatch2(
brandList: Array[com.example.domain.brand.command.CreateBrandCommand]):
com.example.domain.shared.entity.ActionListResult[
com.example.domain.brand.entity.Brand]
=
{
com.example.domain.shared.PreDef.futureWrapper[
Array[com.example.domain.brand.command.CreateBrandCommand]](brandList)
.map[Any](
{
def $anonfun(
x: Array[com.example.domain.brand.command.CreateBrandCommand]):
Any = x.orgId
closure($anonfun)
}
)(/* missing */summon[scala.concurrent.ExecutionContext])
???
}
}
You should build your project with -feature
flag to get more info about where implicit conversion is used in your code.
To get the similar implicits semantics as in Scala 2 use Conversion
type class instead
given futureWrapper[T]: Conversion[T, Future[T]] = Future.successful(_)
// implicit def futureWrapper[T](data: => T): Future[T] = Future.successful(data)
With this change project compiles
if you have more questions like this in the future, https://users.scala-lang.org is a better place. https://scala-lang.org/community/ has some other suggestions for places to get help with Scala
to report a bug here in the issue tracker, you should first be reasonably certain that a compiler bug is the cause, and you should be prepared to make an argument and show evidence that's the case
thanks very much, @SethTisue @SethTisue
Compiler version
3.3.1 If you're not sure what version you're using, run
print scalaVersion
from sbt (if you're running scalac manually, usescalac -version
instead).Minimized code
Output
value orgId is not a member of Array[com.nxin.product.domain.brand.command.CreateBrandCommand]
why the complier treat x as Array[CreateBrandCommand] ?
Expectation