Seite 1 von 1

issue in scala: overridden -=

Verfasst: 10. Jun 2015 13:15
von O_kut
Hello,
I'm not sure if I'm missing something.
I'm trying to use the given operation:

Code: Alles auswählen

  class Store(size: Int) extends scala.collection.mutable.Map[Location, Value] {
    .........

    override def -=(k: Location) = {
      val oldVal = memory(k)
      memory(k) = null
      if (oldVal != null) _free += 1
      this
    }
....
here:

Code: Alles auswählen

  val tmpEloc = interp(e, env, store, classes)
  store(fields(i)) = store(tmpEloc)
  store -= tmpEloc
but I get the following error message:

Code: Alles auswählen

Status: CompilationFailure
solution.scala:202: error: type mismatch;
 found   : store.type (with underlying type StateOOInterp.Store)
 required: StateOOInterp.Location
              store -= tmpEloc
                    ^
Any help is appreciated!

Re: issue in scala: overridden -=

Verfasst: 10. Jun 2015 14:14
von IvaToteva
Hi,

The problem is not with the execution of the statement itself. The code

Code: Alles auswählen

store -= tmpEloc
will execute fine. However, it evaluates to the new store, that is why its type is Store.

If you have added this line at the end of a method (or as a last statement in one of the cases of interp), then the method will return the updated store. If the method specifies Location as its return type, you will get the type mismatch error.

Best,
Iva

Re: issue in scala: overridden -=

Verfasst: 10. Jun 2015 14:26
von O_kut
oh right ... that was kinda confusing. Thanks!!