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

Dependent type is not working in Scala version 3.3.0-RC3 #17181

Closed
chungonn opened this issue Mar 30, 2023 · 13 comments
Closed

Dependent type is not working in Scala version 3.3.0-RC3 #17181

chungonn opened this issue Mar 30, 2023 · 13 comments
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@chungonn
Copy link

chungonn commented Mar 30, 2023

Compiler version 3.3.0-RC3 and 3.3.1-nightly version

Minimized code

The code works from Scala 3.1.x up to 3.2.2
inline def foo[A](inline a: A)(fn: a.type => String): String =
fn(a)

@main def hello() =
val x= foo("hello")( (s: "hello") => s + " world!")
println(s"x = ${x}")

val y = foo(1)((s: 1) => s + " world!")
println(s"y = ${y}")

println("hello, world")

Output

[error] -- [E083] Type Error: /home/chungonn/development/experiments/scala3test/src/main/scala/Main.scala:2:35 
[error] 2 |inline def foo[A](inline a: A)(fn: a.type => String): String =
[error]   |                                   ^^^^^^
[error]   |  (a : A) is not a valid singleton type, since it is not an immutable path
[error]   |
[error]   | longer explanation available when compiling with `-explain`
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed 30 Mar 2023, 11:26:36 am

Expectation

x = hello world!
y = 1 world!

@chungonn chungonn added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 30, 2023
@SethTisue
Copy link
Member

duplicate of #16804?

@chungonn
Copy link
Author

duplicate of #16804?

I does seems like the same bug. I am not sure how compiler interprets between a regular parameter list compared a implicit parameter list.

Also the above will compile, if the inline keyword is removed from the first parameter list

@SethTisue
Copy link
Member

@chungonn you can try it out in the current nightly build — scala-cli -S 3.nightly, or see https://stackoverflow.com/a/40622879/86485

@chungonn
Copy link
Author

@chungonn you can try it out in the current nightly build — scala-cli -S 3.nightly, or see https://stackoverflow.com/a/40622879/86485

@SethTisue I have not tried scala-cli, I only SBT instead for all my Scala work/projects.

I went to the dotty site https://dotty.epfl.ch/ to pick up the nightly build - 3.3.1-RC1-bin-20230328-5c2efc5-NIGHTLY and it is still not working. Should I try to use tmr's nightly build instead?

@chungonn
Copy link
Author

@chungonn you can try it out in the current nightly build — scala-cli -S 3.nightly, or see https://stackoverflow.com/a/40622879/86485

I tried it with scala-cli repl, it is still not working

`➜ ~ scala-cli repl -S 3.3.nightly

Downloading JVM temurin:17
Welcome to Scala 3.3.1-RC1-bin-20230328-5c2efc5-NIGHTLY-git-5c2efc5 (17.0.6, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> inline def foo[A](inline a: A)(fn: a.type => String): String =
| fn(a)
|
-- [E083] Type Error: ----------------------------------------------------------
1 |inline def foo[A](inline a: A)(fn: a.type => String): String =
| ^^^^^^
| (a : A) is not a valid singleton type, since it is not an immutable path
|
| longer explanation available when compiling with -explain
1 error found
`

@SethTisue
Copy link
Member

@chungonn I'm sorry, I was moving too quickly and my suggestion to try it in the nightly build was not really relevant.

the resolution of #16804 is that the code in question should not compile — see Nicolas's remarks. it seems to me that your code should not compile either, unless you're trying to make a case otherwise?

@SethTisue
Copy link
Member

(as an aside, in the future, should you want to use a Scala 3 nightly in sbt rather than scala-cli, see the Stack Overflow link I provided — that's why I included it)

@chungonn
Copy link
Author

(as an aside, in the future, should you want to use a Scala 3 nightly in sbt rather than scala-cli, see the Stack Overflow link I provided — that's why I included it)

Yes, I went to the link and saw your post. I wasn't sure how to setup in SBT for Scala 3. Then I read your notes on the use scala-cli, then I installed scala-cli and followed the instructions given.

Thanks for pointing to that link though

@chungonn
Copy link
Author

@chungonn I'm sorry, I was moving too quickly and my suggestion to try it in the nightly build was not really relevant.

the resolution of #16804 is that the code in question should not compile — see Nicolas's remarks. it seems to me that your code should not compile either, unless you're trying to make a case otherwise?

Yes, my code is not compiling. The case I am raising here is, the same code works for Scala 3.2.x and versions before it. Also the example I provided above shows that the argument constants.

I am confused by Nicolas's remarks, He remarked that that it is a bug, and was fixed in issue #15511 . However, he followed by an example why it should not have worked, as his examples demonstrated the creating new instances of X. I my example, I used 2 singleton types "hello" and 1.

I would assume that my case was incorrectly working prior to Scala 3.3.x, and now from Scala 3.3.x onwards, it is correctly not working, am I right?

@chungonn
Copy link
Author

I have removed the inline keyword from the parameter list and all is compiling. I hope that rest of the app which uses the library will not have problems.

Should I close this issue now?

@SethTisue
Copy link
Member

SethTisue commented Mar 30, 2023

I would assume that my case was incorrectly working prior to Scala 3.3.x, and now from Scala 3.3.x onwards, it is correctly not working, am I right?

that is my understanding

@nicolasstucki can you close the issue if you agree?

@chungonn
Copy link
Author

My apologies, I was in a huge rush yesterday that I just realized my sample code was being commented out hence it was not showing i.e. showing only the last line which is the output. I have edited the issue to uncomment the sample code, it is correctly showing.

@odersky
Copy link
Contributor

odersky commented Mar 31, 2023

OK, I think we can close this now. Good that it was cleared up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

3 participants