Issue #19426 has been updated by Vincent Janelle. Status changed from Unreviewed to Accepted Assignee set to Henrik Lindberg
Blame eric. ---------------------------------------- Bug #19426: parser merges literal hash keys at parse time https://projects.puppetlabs.com/issues/19426#change-94695 * Author: Henrik Lindberg * Status: Accepted * Priority: Normal * Assignee: Henrik Lindberg * Category: language * Target version: * Affected Puppet version: 3.1.0 * Keywords: language hash duplicate-key parser * Branch: ---------------------------------------- When the parser constructs a literal hash, it does this by creating an AstHash for each entry which are then merged. This is a problem because expressions (with potential side effects) will not be evaluated if the merge considers two keys to be equal. Key equality does not take interpolation result into account. <pre> $a = { a=>foo(1), a=>foo(2), a=>foo(3) } $b = { "at${time()}" => 'first', at${time()} = 'second' } </pre> The first assignment produces a result in $a with one key 'a', and foo *was called only once* with the argument '3'. The second example will create only one key since the merge thinks the keys are equal (the key with the value 'second'). Although strange examples, there are no errors or warnings that keys are duplicate. A sane implementation would keep all operations, and execute them. If strict immutability is also enforced, then changing a key would result in an error, if immutability is not strict, then the operation should be allowed (i.e. potentially producing a side effect). The current behavior is simply strange. Suggest this is fixed by letting the parser include each element, and issuing a runtime error on attempt to mutate already set key. (This because it is impossible to statically validate if a function produces a consistent result or not for the same input). -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://projects.puppetlabs.com/my/account -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/groups/opt_out.
