Crystal: Can't use Time in NamedTuple with .to_h conversion

Created on 28 Mar 2017  路  3Comments  路  Source: crystal-lang/crystal

def uni(**args)
  puts "#{args.to_h}"
end

uni(a:123, b: "opa")

uni(a:123, b: "opa", c: Time.now)

Produce an error:
```in /usr/lib/crystal/named_tuple.cr:402: expanding macro

{% begin %}
^

in macro 'macro_206236176' /usr/lib/crystal/named_tuple.cr:402, line 8:



    1. {



    1. :a => self[:a].clone,



    1. :b => self[:b].clone,


  1. > 8. :c => self[:c].clone,


    1. }


undefined method 'clone' for Time
```

version:
Crystal 0.21.1 (2017-03-14) LLVM 4.0.0

bug stdlib

Most helpful comment

Actually, I'll reopen this. Why is there a clone in NamedTuple#to_h in the first place? :-S

All 3 comments

Duplicate of https://github.com/crystal-lang/crystal/pull/4174 (already fixed in master)

Actually, I'll reopen this. Why is there a clone in NamedTuple#to_h in the first place? :-S

@asterite heh, I was asking myself the same question but then I told to myself there must be a reason to that, and went ahead with #4174 ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulcsmith picture paulcsmith  路  3Comments

lgphp picture lgphp  路  3Comments

Papierkorb picture Papierkorb  路  3Comments

TechMagister picture TechMagister  路  3Comments

oprypin picture oprypin  路  3Comments