issue in scala: overridden -=

Benutzeravatar
O_kut
Erstie
Erstie
Beiträge: 22
Registriert: 13. Okt 2008 15:29

issue in scala: overridden -=

Beitrag 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!

IvaToteva
Neuling
Neuling
Beiträge: 10
Registriert: 15. Apr 2015 16:41

Re: issue in scala: overridden -=

Beitrag 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

Benutzeravatar
O_kut
Erstie
Erstie
Beiträge: 22
Registriert: 13. Okt 2008 15:29

Re: issue in scala: overridden -=

Beitrag von O_kut »

oh right ... that was kinda confusing. Thanks!!

Antworten

Zurück zu „Archiv“