aardappel / lobster

The Lobster Programming Language
http://strlen.com/lobster
2.24k stars 121 forks source link

Assertion failure with *= operator #249

Closed MortimerSnerd closed 1 year ago

MortimerSnerd commented 1 year ago

On commit ec7905ebd7de60c89363e4bb3037252cdef7d629

For a class with user defined operator*, the *= operator fails with the following assertion:

Assertion failed: false, file C:\src\lobster\dev\src\lobster\codegen.h, line 654

Writing it out as x = x * y works fine.

Repro code:

import vec

class mat3x4:
   col0: xyzw_f
   col1: xyzw_f
   col2: xyzw_f

   def operator*(o: mat3x4) -> mat3x4:
      return mat3x4{
         o.col0*col0.x + o.col1*col0.y + o.col2*col0.z + xyzw{0.0, 0.0, 0.0, col0.w},
         o.col0*col1.x + o.col1*col1.y + o.col2*col1.z + xyzw{0.0, 0.0, 0.0, col1.w},
         o.col0*col2.x + o.col1*col2.y + o.col2*col2.z + xyzw{0.0, 0.0, 0.0, col2.w}}

let ts = [mat3x4{xyzw_x, xyzw_y, xyzw_z}]
let xs = [mat3x4{xyzw_x, xyzw_y, xyzw_z}]

ts[0] *= xs[0]
// Following line works.
//ts[0] = ts[0] * xs[0]
aardappel commented 1 year ago

Thanks, fixed here: https://github.com/aardappel/lobster/commit/91ee725cf5fe49dc59a608f05065dc3f75651cec

It does not automatically reuse * for *=, they need to be defined separately, such that *= can actually overwrite the value rather than allocate a new one.