bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31688: 26.1.50; Byte compiler confuses two string variables


From: Noam Postavsky
Subject: bug#31688: 26.1.50; Byte compiler confuses two string variables
Date: Sat, 02 Jun 2018 14:02:51 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Gemini Lasswell <gazally@runbox.com> writes:

> Here is a test which succeeds when interpreted and fails when
> byte-compiled. The byte compiler is apparently confusing two string
> variables, or optimizing away one of them.  I've tried it both
> with and without lexical-binding with the same results.
>
> To reproduce, save this to bug.el:
>
> (require 'ert)
> (ert-deftest test-strings-props ()
>   (let* ((str1 "abcdefghij")
>          (obj '(a b))
>          (str2 "abcdefghij"))
>     (put-text-property 0 5 'test obj str2)
>     (should (equal "\"abcdefghij\"" (prin1-to-string str1)))))

I don't think this is a bug, the compiler coalesces equal string
literals.  `put-text-property' modifies the string destructively, so you
shouldn't use it on literals, for the same reason you shouldn't use
destructive operations on quoted list literals.  Another example, not
dependent on compilation:

    (defun foo (prop val)
      (let ((s "xyz"))
        (put-text-property 0 3 prop val s)
        s))

    (foo 'x 1) ;=> #("xyz" 0 3 (x 1))
    (foo 'y 2) ;=> #("xyz" 0 3 (x 1 y 2))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]