record initialization weirdness

Description

If you redundantly define a record as in cmd_bad:

You get this:

Environment

None

Activity

Show:
Seth Hall
May 19, 2014, 6:52 PM

You defined that last one incorrectly...

local cmd_bad = Exec::Command([$cmd=strcmd]);

The square brackets create a record and then you're doing the named ctor thing, so it's a record in a record. Am I misunderstanding something?

Justin Azoff
May 19, 2014, 7:00 PM
Edited

Oh, yes, I know it's wrong. I was helping someone on IRC and they made that mistake.

The issue is how is that not a syntax error and how does it somehow set cmd to "[cmd=echo hi]"?

Jon Siwek
May 19, 2014, 7:05 PM

It's coercing the record in to a string (the type of the first field) where I would expect there might be some type check that could emit an error instead. I'll see if it's an easy fix to do during beta.

Jon Siwek
May 19, 2014, 8:22 PM

The expression list given to a record ctor may currently be comprised of record-field-assignment expressions or any expressions that evaluate in to a record. For all the expressions in the later case, their record fields will get incorporated in to the type of the outer record ctor. Or at least that's what supposed to happen, except the code currently doesn't work if there's more than one such expression.

In light of that, I'm going to change record ctor's expression list to only allow record-field-assignments (which fixes the issue in this ticket). No default scripts rely on the other functionality, which appears to be a relict, and I don't see the use of a record ctor that takes a single expression which evaluates in to a record (you can just use that expression instead of the ctor).

Assignee

Unassigned

Reporter

Justin Azoff

Labels

External issue ID

None

Components

Fix versions

Affects versions

Priority

Low
Configure