Skip to content

super[T] not working inside an anonymous function (e.g. for loop) #4300

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

Closed
scabug opened this issue Feb 25, 2011 · 7 comments
Closed

super[T] not working inside an anonymous function (e.g. for loop) #4300

scabug opened this issue Feb 25, 2011 · 7 comments
Milestone

Comments

@scabug
Copy link

scabug commented Feb 25, 2011

=== What steps will reproduce the problem? ===

trait A {
	def f() = println("A")
}

class B extends A {
	def g() = for(i <- 0 until 1) super[A].f()
	def h() = for(i <- 0 until 1) B.super[A].f()
}

val b = new B()
b.g() // ClassCastException
b.h() // ClassCastException

=== What is the expected behavior? ===

The expected output is

A
A

=== What do you see instead? ===

ClassCastException is thrown, as the compiler tries to cast the anonymous function to A.

=== Additional information ===
http://groups.google.com/group/scala-user/browse_thread/thread/757e3c5efb85c607

=== What versions of the following are you using? ===

  • Scala: 2.8.1
  • Java: 1.6.0_20
  • Operating system: Ubuntu Linux
@scabug
Copy link
Author

scabug commented Feb 25, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4300?orig=1
Reporter: Tomas Mikula (tomas.mikula)

@scabug
Copy link
Author

scabug commented Mar 1, 2011

@axel22 said:
Martin, it was suggested on the meeting that this might have to do something with the typechecker. Would you mind taking a look and reassigning it if it belongs to someone else?

@scabug
Copy link
Author

scabug commented Mar 14, 2011

@odersky said:
(In r24440) Changed Super to fix #4300

@scabug
Copy link
Author

scabug commented Mar 14, 2011

@odersky said:
(In r24441) Closes #4300. No review.

@scabug
Copy link
Author

scabug commented Apr 2, 2015

Manos Koukoutos (manoskouk) said:
This problem seems to persist for traits which can only get mixed in with specific classes. This is true even with indirect references to super[A]:

===== This code reproduces the problem =====

class C 

trait Foo {
  this: C =>
  def fun(x:Int) = x + 1
}

trait Bar extends Foo {
  this: C => 

  super[Foo].fun(42) // OK
 
  ( (x : Int) => super[Foo].fun(x) ) // Buggy

  val foo = super[Foo].fun _
  ( (x : Int) => foo(x) ) // Also buggy
}

===== Compiler output =====

error:
  unrecoverable error
     while compiling: /home/koukouto/garbage/bug.scala
        during phase: globalPhase=erasure, enteringPhase=posterasure
     library version: version 2.11.2
    compiler version: version 2.11.2
  reconstructed args: -Xscript Main -d /tmp/scalascript8189118616202519448.tmp

  last tree to typer: This(<$anon: Function1>)
       tree position: line 16 of /home/koukouto/garbage/bug.scala
              symbol: final <$anon: Function1>
   symbol definition: final class $anonfun extends AbstractFunction1$mcII$sp with Serializable (a ClassSymbol)
      symbol package: <empty>
       symbol owners: <$anon: Function1> -> value <local Bar$class> -> class Bar$class -> <$anon: Object> -> method main -> object Main
           call site: method apply$mcII$sp in package <empty>

== Source file context for tree position ==

    13
    14   val foo = super[Foo].fun _
    15   ( (x : Int) => foo(x) ) // Also buggy
    16 }
    17

exception when typing $anonfun.this.$outer.super[Foo].fun(x)/class scala.reflect.internal.Trees$Apply
Foo does not name a parent class of class C in file /home/koukouto/garbage/bug.scala
exception when typing def apply$mcII$sp(x: Int): Int = $anonfun.this.$outer.super[Foo].fun(x)

===========
scalac version: 2.11.2
Operating system: Ubuntu 14.04

@hrhino
Copy link

hrhino commented Aug 27, 2019

Can't reproduce with Manos's reproducer.

@hrhino hrhino closed this as completed Aug 27, 2019
@som-snytt
Copy link

To clarify, the Manos reproducer crashes 2.11.12 but not 2.12.18.

@SethTisue SethTisue added this to the 2.12.0 milestone Aug 23, 2023
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

4 participants