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

type alias and object with the same name cause type mismatch #7139

Closed
scabug opened this issue Feb 15, 2013 · 7 comments
Closed

type alias and object with the same name cause type mismatch #7139

scabug opened this issue Feb 15, 2013 · 7 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Feb 15, 2013

// test/A.scala
package test {
  object A
}
package object test {
  type A = Int
}
scala> val a = test.A
<console>:10: error: type mismatch;
 found   : test.A.type
 required: Any
Note that A extends Any, not AnyRef.
Such types can participate in value classes, but instances
cannot appear in singleton types or in reference comparisons.
 + "a: test.A.type = " + scala.runtime.ScalaRunTime.replStringOf(`a`, 1000)
                                                                                      ^
@scabug
Copy link
Author

scabug commented Feb 15, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7139?orig=1
Reporter: @rjolly
Affected Versions: 2.10.0
See #5031

@scabug
Copy link
Author

scabug commented Mar 14, 2013

@rjolly said:
Variation:

// A.scala

package test {
  object A {
    def apply(n: A) = n
  }
}
package object test {
  type A = Int
}
scala> import test._
import test._

scala> A(0)
res0: test.A = 0

scala> A(0)
<console>:11: error: test.A.type does not take parameters
              A(0)
               ^

@scabug
Copy link
Author

scabug commented Dec 2, 2014

Jed Wesley-Smith (jedws) said:
This issue isn't limited to the REPL, it also causes compilation issues in multi-module builds. We saw the following symptom:

[error] bad symbolic reference to io.atlassian.aws.AwsAction.Functions encountered in class file 'SQSAction.class'.
[error] Cannot access type Functions in object io.atlassian.aws.AwsAction. The current classpath may be
[error] missing a definition for io.atlassian.aws.AwsAction.Functions, or SQSAction.class may have been compiled against a version that's
[error] incompatible with the one found on the current classpath.
[error] /work/aws-scala/sqs/src/test/scala/io/atlassian/aws/sqs/SQSSpec.scala:48: value ok is not a member of object io.atlassian.aws.sqs.SQSAction
[error]         _ <- handles.headOption.map { h => SQS.changeVisibility(url, h, Duration(5, TimeUnit.SECONDS)) } getOrElse SQSAction.ok(())
[error]                                                                                                                              ^

@scabug
Copy link
Author

scabug commented Dec 3, 2014

@retronym said:
A workaround should be:

package test {
  object A0
}
package object test {
  type A = Int
  val A: A0.type = A0
}

@scabug
Copy link
Author

scabug commented Apr 15, 2015

@retronym said:
Reproduction with the resident compiler:

% scalac sandbox/test.scala
% scalac -Xresident

nsc> sandbox/test2.scala

nsc> sandbox/test2.scala
sandbox/test2.scala:2: error: type mismatch;
 found   : p.X.type
 required: AnyRef
Note that X extends Any, not AnyRef.
Such types can participate in value classes, but instances
cannot appear in singleton types or in reference comparisons.
  private[this] val res1 = (null: p.X.type)
                                    ^

@scabug
Copy link
Author

scabug commented Apr 15, 2015

@retronym said:
At the start of the second run, someone is setting the info of the module class of X to NoType. Find that someone, and we'll be closer to understanding this.

@scabug
Copy link
Author

scabug commented Oct 27, 2016

@lrytz said:
fixed in scala/scala#5482

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