Why does using a 'push' module function lead to an error?

Hello there,

I noticed that when using a push function from a module into another function I get the error “variables from outside the function are read-only and cannot be modified”.

Here is a minimal exemple.

First a module “module.typ”:

#let push() = [
  This is a dummy function
]

Then try to use it in another module and in a function, for instance a “call.typ” module:

#import "module.typ" as m

#m.push()  //no problem there

#let mycall() = {
  m.push()  //here is the error
}

#mycall()

The exact error is:

error: variables from outside the function are read-only and cannot be modified
  ┌─ call.typ:6:2
  │
6│   m.push()
  │   ^

help: error occurred in this call of function `mycall`
  ┌─ call.typ:9:1
  │
9│ #mycall()
  │  ^^^^^^^^

My feeling is that for some reason it interprets m as being a global array which thus cannot be modified from the function.

Changing the function name to any other name (e.g. add) works like a charm. I was wondering if this is supposed to be normal or if I should post a bug report.

Thanks for you help.

1 Like

I think that deserves a bug report! I can reproduce this on my side.

1 Like

Done,

link to the issue:

1 Like

Hey @Gijom, welcome to the forum! I’ve moved your post to Questions and changed your question post’s title to better fit our guidelines: How to post in the Questions category

For future posts, make sure your title is a question you’d ask to a friend about Typst. :wink: