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

Scala 2.10-RC2 possible regression #6697

Closed
scabug opened this issue Nov 21, 2012 · 4 comments
Closed

Scala 2.10-RC2 possible regression #6697

scabug opened this issue Nov 21, 2012 · 4 comments
Assignees
Labels

Comments

@scabug
Copy link

scabug commented Nov 21, 2012

Apologies if this is not a regression, or is intended.

I just tried to recompile one of our basic libs with 2.10-RC2 and hit a bizarre error. It seems to require a perfect storm of things to be the case (i.e. change package nestings, or exact classes and it disappears). The symptom of the problem is that compilation fails with the compiler reporting that some method does not exist. The method is added by implicit conversion and should be there. What is especially odd is that the compilation error disappears depending on the type of that which is to implicitly converted into.

The following is my attempt at a minimal example. Steps to reproduce

  1. Create a project for scala. In package a.b.c create 3 files.
// C.scala
package a.b.c

trait C extends Conversions

object C extends C with d.Functions
```scala
{code:title=Conversions.scala}

package a.b.c

trait Conversions extends d.Conversions

object Conversions extends Conversions
// package.scala

package a.b

package object c extends C
```scal

4. Now create a sub-package d. In d, create 2 files

```scala
// Conversions.scala

package a.b.c.d

import language.implicitConversions

trait Conversions {
  import Conversions._
  implicit def str2todstring(s: String) = new StrLen(s)
}

object Conversions extends Conversions {
  class StrLen(s: String) {
    def strlen = s.length
  }
}
// Functions.scala
package a.b
package c
package d

trait Functions {

  import Conversions._
  val toStrLen = (_ : String).strlen
}
  1. Now compile this using scalac 2.10.0-RC2 and a 1.6 JDK. You will get the compile error in a/b/c/d/Functions.scala:
error: value strlen is not a member of String
val toStrLen = (_ : String).strlen
  1. Now remove the import language.implicitConversions line from a.b.c.d.Conversions.scala and recompile with 2.9.2. It compiles just fine

Please find attached the regression example in a ZIP file regression-minimal.zip.

Please use the files exactly as specified. The issue goes away if, for example, you change the package declarations in the files, or omit unnecessary imports.

@scabug
Copy link
Author

scabug commented Nov 21, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6697?orig=1
Reporter: @oxbowlakes
Affected Versions: 2.10.0-RC2
See #4270
Attachments:

@scabug
Copy link
Author

scabug commented Nov 21, 2012

@oxbowlakes said (edited on Nov 21, 2012 11:06:36 AM UTC):
I have had a torrid time to reproduce this minimally. Here are some oddities

// a.b.c.d.Functions.scala
package a.b //if these 3 package declarations are replaced by a.b.c.d it compiles OK
package c
package d

trait Functions {

  import Conversions._ //omit this line and it compiles OK
  val toStrLen = (_ : String).strlen
}

The above will also fail to compile with the error

error: value strlen is not a member of String
val toStrLen = (_ : String).strlen

@scabug
Copy link
Author

scabug commented Nov 21, 2012

@retronym said:
If you compile with -Xlog-implicits, you can see what is happening. Alternatively, try to insert the call to the implicit conversion manaully.

% squalac -Xlog-implicits *.scala
Functions.scala:8: <str2todstring: error> is not a valid implicit value for String => ?{def strlen: ?} because:
reference to str2todstring is ambiguous;
it is both defined in trait Conversions and imported subsequently by 
import Conversions._
  val toStrLen = (_ : String).strlen
                    ^
Functions.scala:8: error: value strlen is not a member of String
  val toStrLen = (_ : String).strlen
                              ^
one error found
% squalac -Xlog-implicits *.scala
Functions.scala:8: error: reference to str2todstring is ambiguous;
it is both defined in trait Conversions and imported subsequently by 
import Conversions._
  val toStrLen = str2todstring((_ : String)).strlen
                 ^
one error found

Before the fix for #4270, this code was accepted.

@scabug scabug closed this as completed Nov 21, 2012
@scabug
Copy link
Author

scabug commented Nov 21, 2012

@retronym said:
That setting doesn't change the result, it just gives you a more detailed diagnosis of why the implicit was not used.

IntelliJ doesn't do very well with multi-line compiler error messages; I think the in-progress work to integrate directly with the SBT builder might help out. But for bug reports here, its best if you reproduce them using the command line scalac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants