zxul767 / lox

An interpreter for the Lox language
1 stars 0 forks source link

figure out how to assert types generically #27

Closed zxul767 closed 1 year ago

zxul767 commented 1 year ago

the goal is to be able to unify the following methods (in LoxNativeClass):

  static LoxString assertString(LoxInstance instance) {
    assert (instance instanceof LoxString)
        : "instance was expected to be a LoxString";
    return (LoxString)instance;
  }

  static LoxList assertList(LoxInstance instance) {
    assert (instance instanceof LoxList)
        : "instance was expected to be a LoxList";
    return (LoxList)instance;
  }

but using generics directly doesn't seem to work due to generic type erasure.

zxul767 commented 1 year ago

Fixed by 20ddad64cb450d4fbf7716823b0331067f066eea