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

Overload resolution should not consider default arguments #8197

Closed
scabug opened this issue Jan 29, 2014 · 30 comments
Closed

Overload resolution should not consider default arguments #8197

scabug opened this issue Jan 29, 2014 · 30 comments

Comments

@scabug
Copy link

scabug commented Jan 29, 2014

ScalaFX does not compile with Scala 2.11-M8. It builds fine with Scala 2.10.3 (and 2.9.3). There are a couple of errors related to type parameters. Here what you get if you try to compile ScalaFX 1.0.0-M7 with Scala 2.11.0-M8:

[error] D:\ScalaFX\scalafx.hg-publish\scalafx\src\main\scala\scalafx\scene\control\Skinnable.scala:43: type mismatch;
[error]  found   : javafx.beans.property.ObjectProperty[javafx.scene.control.Skin[_]]
[error]  required: scalafx.beans.property.ObjectProperty[javafx.scene.control.Skin[_ <: javafx.scene.control.Skinnable]]
[error]   def skin: ObjectProperty[jfxsc.Skin[_]] = delegate.skinProperty
[error]                                                      ^
[error] D:\ScalaFX\scalafx.hg-publish\scalafx\src\main\scala\scalafx\scene\control\TableColumn.scala:100: type mismatch;
[error]  found   : javafx.event.EventType[javafx.scene.control.TableColumn.CellEditEvent[_, _]]
[error]  required: javafx.event.EventType[javafx.scene.control.TableColumn.CellEditEvent[S, T]]
[error] Note: javafx.scene.control.TableColumn.CellEditEvent[_, _] >: javafx.scene.control.TableColumn.CellEditEvent[S, T], but Java-defined class EventType is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ >: javafx.scene.control.TableColumn.CellEditEvent[S, T]`. (SLS 3.2.10)
[error]       this(new jfxsc.TableColumn.CellEditEvent(table, pos, eventType, newValue))
[error]                                                            ^
[error] D:\ScalaFX\scalafx.hg-publish\scalafx\src\main\scala\scalafx\scene\web\WebEvent.scala:69: type mismatch;
[error]  found   : scalafx.event.EventType[javafx.scene.web.WebEvent[_]]
[error]  required: javafx.event.EventType[javafx.scene.web.WebEvent[T]]
[error]   def this(source: Any, eventType: EventType[jfxsw.WebEvent[_]], data: T) = this(new jfxsw.WebEvent(source, eventType, data))
[error]                                                                                                             ^
[error] three errors found
[error] (scalafx/compile:compile) Compilation failed

You can download source code that was tested from here:
https://code.google.com/p/scalafx/downloads/detail?name=scalafx-1.0.0-M7-sources.jar
To build you need Java 1.7.0_45 or newer and SBT 0.13.1
You need to create environment variable JAVA_HOME pointing to the location of JDK. Details are in README-SBT.txt in the root directory.

@scabug
Copy link
Author

scabug commented Jan 29, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8197?orig=1
Reporter: Jarek Sacha (jpsacha)
Affected Versions: 2.11.0-M8
See #6169

@scabug
Copy link
Author

scabug commented Jan 29, 2014

@adriaanm said:
Thanks for reporting! I think this is because of the fix for #1786, and it looks related to #8198.
The fix for #1786 is useful, but it now also infers more precise bounds in expected types (it was mostly intended to have more precise types for "provided things").

I haven't checked, but is it legal in java to assign skinProperty to a variable with type javafx.scene.control.Skin<C extends Skinnable>,
where ObjectProperty<Skin<?>> skinProperty()??

@scabug
Copy link
Author

scabug commented Jan 30, 2014

Jarek Sacha (jpsacha) said:
To clarify, the bug report is in response to 2.11.0-M8 announcement requesting examples of code that does not compile but compiled with 2.10.

The code that does not compile looks like this

import scalafx.beans.property.ObjectProperty

def skin: ObjectProperty[javafx.scene.control.Skin[_]] = delegate.skinProperty

skinProperty is a JavaFX method of javafx.scene.control.Skinnable with returning type ObjectProperty<javafx.scene.control.Skin<?>>, so the type parameters do match here. I think the problem is that javafx.scene.control.Skin is defined as

Interface Skin<C extends Skinnable>

This may be a bug in JavaFX API, most likely skinProperty should be returning ObjectProperty<javafx.scene.control.Skin<C extends Skinnable>>. Or maybe it is defined as is to avoid some type parametrization cycle: Skin defined in terms Skinnable, and Skinnable in terms of Skin. This somehow type-checks in Java and Scala 2.10.
A work around, in this case, is to force type-cast:

import scalafx.beans.property.ObjectProperty

def skin: ObjectProperty[jfxsc.Skin[_ <: jfxsc.Skinnable]] = {
   val p = delegate.skinProperty
   p.asInstanceOf[javafx.beans.property.ObjectProperty[jfxsc.Skin[_ <: jfxsc.Skinnable]]]
}

though it is quite ugly.

Note that there is an implicit conversion from javafx.beans.property.ObjectProperty to scalafx.beans.property.ObjectProperty, which may or may not be involved somehow:

package scalafx.beans.property

object ObjectProperty {
  
  implicit def sfxObjectProperty2jfx[T <: Any](op: ObjectProperty[T]) = op.delegate
...
}

where op.delegate is of type {noformat}javafx.beans.property.ObjectProperty[T]{noformat}.

I did not find yet workarounds for the other compilation errors shown in the original report. The third error is a bit similar. But the second is reporting some type invariance issues, it may be a different thing.

@scabug
Copy link
Author

scabug commented Jan 30, 2014

@adriaanm said:
Thanks for the detailed follow-up! I'm working on a fix here: https://github.com/adriaanm/scala/compare/t6169

@scabug
Copy link
Author

scabug commented Jan 30, 2014

Jarek Sacha (jpsacha) said:
Do you think this fix will also resolve the second error message?

[error] D:\ScalaFX\scalafx.hg-publish\scalafx\src\main\scala\scalafx\scene\control\TableColumn.scala:100: type mismatch;
[error]  found   : javafx.event.EventType[javafx.scene.control.TableColumn.CellEditEvent[_, _]]
[error]  required: javafx.event.EventType[javafx.scene.control.TableColumn.CellEditEvent[S, T]]
[error] Note: javafx.scene.control.TableColumn.CellEditEvent[_, _] >: javafx.scene.control.TableColumn.CellEditEvent[S, T], but Java-defined class EventType is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ >: javafx.scene.control.TableColumn.CellEditEvent[S, T]`. (SLS 3.2.10)
[error]       this(new jfxsc.TableColumn.CellEditEvent(table, pos, eventType, newValue))

@scabug
Copy link
Author

scabug commented Jan 31, 2014

Stephen Compall (s11001001) said:
jpsacha: I don't think this #8198 related, but see #6169 for much further discussion. It isn't a bug in the JavaFX API, because some of the bounds that it infers yield unspeakable existential types in Java, mostly on the *Builders. With a fix for 6169, your interactions with JavaFX types should get smoother and less casty overall.

@scabug
Copy link
Author

scabug commented Jan 31, 2014

Stephen Compall (s11001001) said:
...well, except insofar as the non-F-bound case in #1786 interacts with the non-F-bound case of #6169 to cause your issues with non-F-bounded existentials, something similar would occur between #8198 and #6169, were the former fixed but not the latter.

@scabug
Copy link
Author

scabug commented Feb 4, 2014

@adriaanm said:
I can confirm the first error is due to #6169. The other two are separate :(

@scabug
Copy link
Author

scabug commented Feb 6, 2014

@adriaanm said (edited on Feb 6, 2014 6:32:35 PM UTC):
note to self: can this subsume the fix for #1786

@scabug
Copy link
Author

scabug commented Feb 13, 2014

@adriaanm said:
Jarek, could you give the latest nightly a shot? I hope we've fixed/reverted the existential regressions :)

@scabug
Copy link
Author

scabug commented Feb 13, 2014

Jarek Sacha (jpsacha) said:
I assume that I can compile with the latest nightly using

sbt> ++2.11.0-SNAPSHOT
sbt> compile

Looks that is is using 2.11.0-20140213.015456-546. Still similar errors:

...
[info] downloading http://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.0/scala-reflect-2.10.0.jar ...
[info]  [SUCCESSFUL ] org.scala-lang#scala-reflect;2.10.0!scala-reflect.jar (6573ms)
[info] downloading https://oss.sonatype.org/content/repositories/snapshots/org/scala-lang/scala-reflect/2.11.0-SNAPSHOT/scala-reflect-2.11.0-20140213.015456-546.jar ...
[info]  [SUCCESSFUL ] org.scala-lang#scala-reflect;2.11.0-SNAPSHOT!scala-reflect.jar (9448ms)
[info] Done updating.
[info] 'compiler-interface' not yet compiled for Scala 2.11.0-20140212-225812-2240464dea. Compiling...
[info]   Compilation completed in 11.462 s
[error] D:\scalafx.hg\scalafx\src\main\scala\scalafx\scene\control\TableColumn.scala:100: type mismatch;
[error]  found   : javafx.event.EventType[javafx.scene.control.TableColumn.CellEditEvent[_, _]]
[error]  required: javafx.event.EventType[javafx.scene.control.TableColumn.CellEditEvent[S, T]]
[error] Note: javafx.scene.control.TableColumn.CellEditEvent[_, _] >: javafx.scene.control.TableColumn.CellEditEvent[S, T], but Java-defined class EventType is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ >: javafx.scene.control.TableColumn.CellEditEvent[S, T]`. (SLS 3.2.10)
[error]       this(new jfxsc.TableColumn.CellEditEvent(table, pos, eventType, newValue))
[error]                                                            ^
[error] D:\scalafx.hg\scalafx\src\main\scala\scalafx\scene\web\WebEvent.scala:69: type mismatch;
[error]  found   : scalafx.event.EventType[javafx.scene.web.WebEvent[_]]
[error]  required: javafx.event.EventType[javafx.scene.web.WebEvent[T]]
[error]   def this(source: Any, eventType: EventType[jfxsw.WebEvent[_]], data: T) = this(new jfxsw.WebEvent(source, eventType, data))
[error]                                                                                                             ^
[error] two errors found

@scabug
Copy link
Author

scabug commented Feb 13, 2014

@adriaanm said:
Thanks, looks like we made some progress. I'll look into the remaining ones tomorrow.

@scabug
Copy link
Author

scabug commented Feb 14, 2014

Jarek Sacha (jpsacha) said:
With latest nightly 20140214.015224-547, I no longer have errors reported above. I still have one regression:

[error] D:\scalafx.hg\scalafx-demos\src\main\scala\scalafx\controls\SplitMenuButtonDemo.scala:48: ambiguous reference to overloaded definition,
[error] both constructor SplitMenuButton in class SplitMenuButton of type (items: scalafx.scene.control.MenuItem*)scalafx.scene.control.SplitMenuButton
[error] and  constructor SplitMenuButton in class SplitMenuButton of type (delegate: javafx.scene.control.SplitMenuButton)scalafx.scene.control.SplitMenuButton
[error] match argument types ()
[error]           new SplitMenuButton {
[error]               ^
[error] one error found

@scabug
Copy link
Author

scabug commented Feb 15, 2014

@adriaanm said (edited on Feb 15, 2014 4:05:13 AM UTC):
Could you explain how this is supposed to typecheck?

 new SplitMenuButton {
            text = "SplitMenuButton 1"
            onAction = {ae: ActionEvent => {println(ae.eventType + " occurred on SplitMenuButton")}}
            items = List(
              new MenuItem("MenuItem A") {
                onAction = {ae: ActionEvent => {println(ae.eventType + " occurred on Menu Item A")}}
              },
              new MenuItem("MenuItem B")
            )
          },

@scabug
Copy link
Author

scabug commented Feb 15, 2014

@adriaanm said:
In other words, a self-contained repro would really help -- running out of time for the RC deadline. Thanks for all your help so far!

@scabug
Copy link
Author

scabug commented Feb 15, 2014

Jarek Sacha (jpsacha) said (edited on Feb 15, 2014 5:11:30 AM UTC):
I am not sure what you mean above by 'type check'. It is important to add "import scalafx.Includes._" that pulls a lot of implicit that may "type check" the code above, for instance, for assignment "onAction = {ae: ActionEvent => ...}"

new SplitMenuButton() should get a default constructor parameter supplied (delegate = new jfxsc.SplitMenuButton()).

Sorry I an not able to provide a reduced example. In simple examples similar code with one of the constructor had a default parameter and other has a has a T* argument compiles fine. There looks to be something more involved here. I look more tomorrow. Some other way of simplifying this is below.

A thing that may help is that if I use scalafx library (build for 2.10) but 2.11.0-M8 compiler and try to instantiate SplitMenuButton

import scalafx.scene.control.SplitMenuButton

class A { 
  val a = new SplitMenuButton()
}

I get similar error

[error] ....scala:6: ambiguous reference to overloaded definition,
[error] both constructor SplitMenuButton in class SplitMenuButton of type (items: scalafx.scene.control.MenuItem*)scalafx.scene.control.SplitMenuButton
[error] and  constructor SplitMenuButton in class SplitMenuButton of type (delegate: javafx.scene.control.SplitMenuButton)scalafx.scene.control.SplitMenuButton
[error] match argument types ()
[error]   val a = new SplitMenuButton
[error]           ^
[error] one error found

Just for a reference SBT setup looks like this:

scalaVersion := "2.11.0-M8"

libraryDependencies += "org.scalafx" % "scalafx_2.10" % "1.0.0-M7"

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

scalacOptions ++= Seq("-unchecked", "-deprecation", "–explaintypes", "–Xlint")

unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_HOME") + "/jre/lib/jfxrt.jar"))

I need to run, I will try to attach a sample project tomorrow.

@scabug
Copy link
Author

scabug commented Feb 19, 2014

@adriaanm said:
minimized:

Welcome to Scala version 2.11.0-M8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class Foo(val x: String = "a") {
     |   def this(bla: Int*) {
     |     this("a")
     |   }
     | }
defined class Foo

scala> new Foo
<console>:10: error: ambiguous reference to overloaded definition,
both constructor Foo in class Foo of type (bla: Int*)Foo
and  constructor Foo in class Foo of type (x: String)Foo
match argument types ()
              new Foo
              ^
Welcome to Scala version 2.10.4-RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class Foo(val x: String = "a") {
     |   def this(bla: Int*) {
     |     this("a")
     |   }
     | }
defined class Foo

scala> new Foo
res0: Foo = Foo@77892f2c

@scabug
Copy link
Author

scabug commented Feb 19, 2014

@adriaanm said:
Looks related to #4728

@scabug
Copy link
Author

scabug commented Feb 20, 2014

@adriaanm said:
Git bisect says it regressed in scala/scala@6c7e6eb

@scabug
Copy link
Author

scabug commented Feb 20, 2014

@adriaanm said:
Which overload do you expect to be picked?

@scabug
Copy link
Author

scabug commented Feb 20, 2014

@adriaanm said:
scala/scala#3562

@scabug
Copy link
Author

scabug commented Feb 20, 2014

@paulp said:
Great commit message though.

@scabug
Copy link
Author

scabug commented Feb 20, 2014

@adriaanm said:
The commit in which it "regressed" merely revealed an existing flaw by cleaning up the rest of the logic. I'm commenting over at the PR what I think should've been the real fix, but I'm not sure we should go there days before RC1.

@scabug
Copy link
Author

scabug commented Feb 20, 2014

@adriaanm said:
EDIT: it's mostly spec exegesis, I think the PR I submitted is an accurate fix. Clarifying with scala/scala-dist#132

@scabug scabug closed this as completed Feb 21, 2014
@scabug
Copy link
Author

scabug commented Feb 21, 2014

@retronym said:
Followup: scala/scala#3572

@scabug
Copy link
Author

scabug commented Feb 23, 2014

Jarek Sacha (jpsacha) said:
ScalaFX now compiles and runs with 2.11.0-SNAPSHOT (20140222) !!!
Thanks guys :)

@scabug
Copy link
Author

scabug commented Feb 23, 2014

@adriaanm said:
Thank you for reporting, minimizing and testing!!

@scabug
Copy link
Author

scabug commented Feb 25, 2014

@adriaanm said:
Better fix at scala/scala#3583

I don't expect this to break scalafx since we put in a regression test, but please let me know if somehow it breaks anything for you.

@scabug
Copy link
Author

scabug commented Feb 26, 2014

Jarek Sacha (jpsacha) said:
ScalaFX runs with 2.11.0-20140226.015145-560, though I am not sure if scala/scala#3583 is in it already.

@scabug
Copy link
Author

scabug commented Feb 26, 2014

@adriaanm said:
Yep. Thanks for confirming!

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

2 participants