这是indexloc提供的服务,不要输入任何密码
Skip to content

References must keep track of their origin #470

@hellerve

Description

@hellerve

Currently, references can be invalidated by invalidating their origin inside their scope.

(defn use-up [x] ())

(defn main []
  (let-do [a [@"hi"]
           n (Array.nth &a 0)]
    (use-up a)
    (println* n))) ; we used a already! this is bad!

It is also possible to set references to point to values in a more short-lived scope:

(defn main []
  (let-do [x ""]
    (let [a [@"hi"]]
      (set! x (Array.nth &a 0)))
    (println* x))) ; a was already dropped!

Both of these can be prevented by checking the origin of a reference and whether the origin scope still exists; an error could be emitted if it doesn’t.

Cheers

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions