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
A single structural type cannot match both kinds of zero-arg methods #4506
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4506?orig=1 |
Todd Vierling (tvierling) said: |
@magarciaEPFL said: Details at http://lampsvn.epfl.ch/trac/scala/changeset/24029 |
@paulp said: Maybe if we had union types and could say def fn(x: { def f: Int } <or> { def f(): Int}): Int = x.f then we could at least work around it, even if that is pretty ugly. But as it stands even that outlet is unavailable. |
Todd Vierling (tvierling) said: https://groups.google.com/d/topic/scala-language/0NLRyix9HjA/discussion |
@harrah said: Related, I don't see what in the spec allows you to do the opposite and override a method with an empty parameter list with a parameterless method, but the compiler doesn't complain: scala> class A { def x: Int = 3 }
defined class A
scala> class B extends A { override def x(): Int = 4 }
defined class B |
@harrah said: |
@odersky said: |
@paulp said: |
@Ichoran said: Observe: trait T { def x(): Int }
class C extends T { def x = 5 } // Works
trait U { def y: Int }
class D extends U { def y() = 5 } // Works But I'm supposed to keep these parens-or-not straight just so structural typing will work? Not likely! |
Commit Message Bot (anonymous) said: Mostly new command line options: -Xlint // basically, the ones which aren't noisy Some accumulated motivations: The wontfix resolution of ticket #4506 indicates that "def foo" and "def I think it would be better if the warning about "def foo()" overriding trait Me { def f(): Int } // error: Int does not take parameters // compiles // error: Int does not take parameters. Mmph, how can a method The warning about a method contains a reference to a type which is less |
=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
=== What is the expected behavior? ===
The line marked with [*] should compile and work. This matches a trait/class containing {def get(): T} with a structural type declared as {def get: T}.
The reason I think this is the appropriate solution has to do with source code calling conventions. Since methods declared without parens can only be called without them, but both forms are callable without parens, then the structural type forcing no-paren usage should match both trait/class forms.
=== What do you see instead? ===
Compile errors as noted above, requiring two separate structural types to deal with this issue.
=== Additional information ===
See issue #2810 for a symptom of this problem, which was "fixed" by changing the method signature in only one library class.
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: