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

Spurious type error when object defined and returned from a block #1201

Closed
scabug opened this issue Aug 8, 2008 · 5 comments
Closed

Spurious type error when object defined and returned from a block #1201

scabug opened this issue Aug 8, 2008 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Aug 8, 2008

In 2.7.1 final

{ object Bar ; Bar }

causes type error

<console>:4: error: type mismatch;
 found   : Bar.type(in object $$iw) where type Bar.type(in object $$iw) <: Bar with Singleton
 required: Bar.type(in value res0) forSome { type Bar.type(in value res0) <: Bar(in value res0) with Singleton; type Bar(in value res0) <: java.lang.Object with ScalaObject }
       val res0 = 

Whereas the somewhat similar code

{class Bar; new Bar()}

results in

res1: java.lang.Object with ScalaObject = Bar$$1@6f9f88

The first example should probably result in a ScalaObject with Singleton or similar. And, in fact, explicitly typing the block solves the problem

{object Bar; Bar}:ScalaObject with Singleton
res2: ScalaObject with Singleton = Bar$$2$$@189b9bd
@scabug
Copy link
Author

scabug commented Aug 8, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1201?orig=1
Reporter: @JamesIry
See #4876

@scabug
Copy link
Author

scabug commented Aug 8, 2008

@JamesIry said:
This may be related to #1195

@scabug
Copy link
Author

scabug commented Aug 8, 2008

@JamesIry said:
ScalaObject might be all that should be inferred. That's what this code unifies to:

object Bar
object Foo
var x = 1
val foo = if (x == 1) Foo else Bar

foo: ScalaObject = Foo$$@103c520

@scabug
Copy link
Author

scabug commented Jul 7, 2011

@SethTisue said:
any chance of this bug getting some attention? there are a lot of ways to trigger this: see also #1195, #4171, plus this one (very similar to #4171) I found today:

scala> { class A; class B extends A; classOf[B] }
<console>:7: error: type mismatch;
 found   : java.lang.Class[B(in value res4)] where type B(in value res4) <: A with ScalaObject
 required: java.lang.Class[_ <: A with ScalaObject]
       val res4 =
           ^

@scabug
Copy link
Author

scabug commented Feb 12, 2012

@paulp said:
Fixed in 7a6fa80937 or 7a6fa80937^ .

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