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

Methods with ConstantType results get the inhabitant of ConstantType as their body #8564

Closed
scabug opened this issue May 5, 2014 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 5, 2014

Copying from the discussion here: https://groups.google.com/forum/#!topic/scala-internals/QBjjb5gTQKI

A repl session in 2.11 (works the same way in 2.10):

scala> def noisyIdentity(x: AnyRef): x.type = {
     | println("got " + x)
     | x
     | }
noisyIdentity: (x: AnyRef)x.type

scala> noisyIdentity("test")
res0: String = test

// Even more weird:
scala> noisyIdentity(new java.lang.String("test"))
got test
res1: String = test

As you see, println did not get executed: the body of the method got replaced by the inhabitant of the ConstantType.

@scabug
Copy link
Author

scabug commented May 5, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8564?orig=1
Reporter: George Leontiev (folone)
Affected Versions: 2.10.4, 2.11.0

@scabug
Copy link
Author

scabug commented May 5, 2014

@milessabin said:
Also, from the discussion, whatever the decision about this case, the following should continue to behave as it does currently,

scala> trait Assoc[K] { type V ; val value: V }
defined trait Assoc
 
scala> def mkAssoc[V0](k: String, v: V0): Assoc[k.type] { type V = V0 } =
     |   new Assoc[k.type] { type V = V0 ; val value = v }
mkAssoc: [V0](k: String, v: V0)Assoc[k.type]{type V = V0}
 
scala> implicit def nameAssoc = mkAssoc("Name", "Mary")
nameAssoc: Assoc[String("Name")]{type V = String}
 
scala> implicit def ageAssoc = mkAssoc("Age", 23)
ageAssoc: Assoc[String("Age")]{type V = Int}
 
scala> def lookup(k: String)(implicit assoc: Assoc[k.type]): assoc.V = assoc.value
lookup: (k: String)(implicit assoc: Assoc[k.type])assoc.V
 
scala> lookup("Name")
res0: String = Mary
 
scala> lookup("Age")
res1: Int = 23

@scabug
Copy link
Author

scabug commented Aug 11, 2016

@milessabin said:
Also fixed on my SIP-23 branch. I'll assign to 2.12.1.

@scabug
Copy link
Author

scabug commented Aug 12, 2016

@SethTisue said:
scala/scala#5310

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

5 participants