Inner classes and apply method

77 views
Skip to first unread message

Holger

unread,
Aug 3, 2012, 12:55:27 PM8/3/12
to scala...@googlegroups.com
Hello,

I have a problem when I implicitly call the apply method of an outer class from an inner class.

Minimal example:

class Outer {

  self =>

  def apply( position : Inner ) : Boolean = true

  class Inner( ) {

    def testMe = {
      self.apply( this ) // a) this works
      self( this ) // b) this does not work!
    }
  }
}

When I leave out the '.apply' as in b), I get the error message
type mismatch;  found   : Outer.this.Inner  required: _1.Inner where val _1: Outer

I'm using Scala IDE for Eclipse    2.0.2.v-2_09-201207120929-81d0972

Any ideas?


Greetings,

Holger

Sonnenschein

unread,
Aug 5, 2012, 7:08:28 AM8/5/12
to scala...@googlegroups.com
Hi Holger,

that's really strange. Further boiled down:

class Outer {
  def apply( position : Inner ) {}
  class Inner
  apply(new Inner)
  this (new Inner) // error
}

Although the call will correctly be mapped to apply - as we can demonstrate by altering the type of position to Outer#Inner - the compiler seems to assume "for a moment" that it is a constructor call. In that case you were not be able to pass an inner class of the instance prior to its creation.

So AFAICS this could become a JIRA issue.

Peter

Holger

unread,
Aug 5, 2012, 12:29:02 PM8/5/12
to scala...@googlegroups.com


Am Sonntag, 5. August 2012 13:08:28 UTC+2 schrieb Sonnenschein:

So AFAICS this could become a JIRA issue.


Thanks for your answer! As a (relative) Scala newbie I was thinking I had misunderstood some language feature.

sschaef

unread,
Aug 5, 2012, 1:26:13 PM8/5/12
to scala...@googlegroups.com
I think it is speced this way. See SLS: http://www.scala-lang.org/docu/files/ScalaReference.pdf (section 6.5)

Sonnenschein

unread,
Aug 7, 2012, 3:39:33 AM8/7/12
to scala...@googlegroups.com
Where exactly in the spec? I wasn't able to find a resolution in 6.5. Constructor calls are not the same as calls to apply().

Holger

unread,
Aug 7, 2012, 12:58:49 PM8/7/12
to scala...@googlegroups.com


Am Sonntag, 5. August 2012 19:26:13 UTC+2 schrieb sschaef:
I think it is speced this way. See SLS: http://www.scala-lang.org/docu/files/ScalaReference.pdf (section 6.5)


 If the compiler assumes that it is a constructor call, then at least the error message is quite misleading.

Jason Zaugg

unread,
Aug 8, 2012, 1:56:59 AM8/8/12
to Holger, scala...@googlegroups.com
It's a bug, i've lodged it:

https://issues.scala-lang.org/browse/SI-6206

-jason
Reply all
Reply to author
Forward
0 new messages