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

Wrong types when using builder pattern from Java #21524

Open
wjoel opened this issue Aug 31, 2024 · 3 comments
Open

Wrong types when using builder pattern from Java #21524

wjoel opened this issue Aug 31, 2024 · 3 comments

Comments

@wjoel
Copy link
Contributor

wjoel commented Aug 31, 2024

Compiler version

3.4.3, and all previous versions of Scala 3 that I've tested. Crashes on 3.5.0, fixed by #21522, but it has the same (wrong) types as 3.4.3 after that fix.

Minimized code

//> using dep io.github.jwharm.javagi:gtk:0.10.2

import org.gnome.gtk.{Unit => _, _}

object Main {
  val w = Box.builder() // widget
    .setOrientation(Orientation.VERTICAL)
    .setHalign(Align.START)
    .build()
  val b1 = Box.builder() // box
    .setHalign(Align.START)
    .build()
  val b2 = Box.builder() // box
    .setOrientation(Orientation.VERTICAL)
    .setHomogeneous(true)
    .setHalign(Align.START)
    .build()
  val b3 = Box.builder() // box
    .setHalign(Align.START)
    .setHomogeneous(true)
    .build()
  val error1 = Box.builder() // error
    .setOrientation(Orientation.VERTICAL)
    .setHalign(Align.START)
    .setHomogeneous(true)
    .build()
  val error2 = Box.builder() // error
    .setHalign(Align.START)
    .setOrientation(Orientation.VERTICAL)
    .build()
}

Output

Compiling project (Scala 3.4.3, JVM (22))
[error] ./Main.scala:23:16
[error] value setHomogeneous is not a member of org.gnome.gtk.Box#Builder[? <: org.gnome.gtk.Box#Builder[?]]#B#B²
[error] 
[error] where:    B  is a type in trait Builder² with bounds <: io.github.jwharm.javagi.gobject.Builder³[B]
[error]           B² is a type in class Builder⁴ with bounds <: org.gnome.gtk.Widget#Builder⁴[B²]
[error] ./Main.scala:28:16
[error] value build is not a member of org.gnome.gtk.Box#Builder[? <: org.gnome.gtk.Box#Builder[?]]#B#B²
[error] 
[error] where:    B  is a type in class Builder² with bounds <: org.gnome.gtk.Widget#Builder²[B]
[error]           B² is a type in trait Builder³ with bounds <: io.github.jwharm.javagi.gobject.Builder⁴[B²]
Error compiling project (Scala 3.4.3, JVM (22))
Compilation failed

Expectation

The code should compile, as it does when using Scala 2.13. Also, the type of the first assignment should be a Box (as on Scala 2, and Java), not a Widget.

I believe this may be related to #16779.

@wjoel wjoel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 31, 2024
@som-snytt
Copy link
Contributor

som-snytt commented Aug 31, 2024

Maybe #13841 which turns on a package-private parent. (I haven't looked at this example yet.) That ticket has an open PR.

Edit: I applied both fixes, but it doesn't change this result.

@wjoel
Copy link
Contributor Author

wjoel commented Sep 1, 2024

Thanks for testing that, @som-snytt! Too bad it didn't help.

I'm now even more convinced that this is related, and perhaps a duplicate of, #16779. It seems we end up with those path-dependent types in Scala 3 when using Java interfaces that have wildcard types and "interesting" inheritance, but not in Scala 2.

@som-snytt
Copy link
Contributor

The "use Java rules to look up types" was forward-ported, and I noticed it wasn't quite a clean port, so it wouldn't surprise me that additional subtlety is at play. (That's as far as I got with that angle.)

@Gedochao Gedochao added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants