Carp/examples/bugs.carp
2018-02-05 08:17:09 +01:00

41 lines
918 B
Plaintext

;; This file contains examples of unsolved bugs
(load "Debug.carp")
(Debug.sanitize-addresses)
(project-set! "printAST" "true")
;; This shouldn't compile:
;; (defn faulty-repeat [n inpt]
;; (let [str ""]
;; (do
;; (for [i 0 n]
;; (set! str &(append @str @inpt)))
;; @str)))
;; (defn main []
;; (let [strings (faulty-repeat 20 "x")]
;; (IO.println &strings)))
;; ;; Dangling reference to member variable.
;; (deftype S [f String])
;; (defn main []
;; (let [s (S.init @"hello")
;; r (S.f &s)
;; _ (S.set-f s @"bye")]
;; (IO.println r)))
;; ;; Dangling reference to variable.
;; (defn main []
;; (let [s @"hello"
;; r &s]
;; (do (String.delete s)
;; (IO.println r))))
;; Problem with string deallocation in branches.
(deftype Foo [])
(defn f [x] (let [_ (the &Foo x)] ()))
(defn ifmem []
(if false
(f &(Foo.init))
()))