Skip to content

Commit c93ffcb

Browse files
committed
Merge pull request #1254 from xzyfer/fix/map-duplicate-keys
Fix erroneous duplicate map key errors
2 parents 256f05b + 541b644 commit c93ffcb

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

debugger.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
452452
cerr << ind << "Map " << expression;
453453
cerr << " (" << pstate_source_position(node) << ")";
454454
cerr << " [Hashed]" << endl;
455-
// for (auto i : expression->elements()) {
456-
// debug_ast(i.first, ind + " key: ");
457-
// debug_ast(i.second, ind + " val: ");
458-
// }
455+
for (auto i : expression->elements()) {
456+
debug_ast(i.first, ind + " key: ");
457+
debug_ast(i.second, ind + " val: ");
458+
}
459459
} else if (dynamic_cast<List*>(node)) {
460460
List* expression = dynamic_cast<List*>(node);
461461
cerr << ind << "List " << expression;

eval.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,24 @@ namespace Sass {
393393
Expression* Eval::operator()(Map* m)
394394
{
395395
if (m->is_expanded()) return m;
396+
397+
// make sure we're not starting with duplicate keys.
398+
// the duplicate key state will have been set in the parser phase.
399+
if (m->has_duplicate_key()) {
400+
To_String to_string(&ctx);
401+
error("Duplicate key \"" + m->get_duplicate_key()->perform(&to_string) + "\" in map " + m->perform(&to_string) + ".", m->pstate());
402+
}
403+
396404
Map* mm = new (ctx.mem) Map(m->pstate(),
397405
m->length());
398406
for (auto key : m->keys()) {
399-
*mm << std::make_pair(key->perform(this), m->at(key)->perform(this));
407+
*mm << std::make_pair(key->perform(this), m->at(key)->perform(this));;
400408
}
401409

402-
// check for duplicate keys
410+
// check the evaluated keys aren't duplicates.
403411
if (mm->has_duplicate_key()) {
404412
To_String to_string(&ctx);
405-
error("Duplicate key \"" + mm->get_duplicate_key()->perform(&to_string) + "\" in map " + m->perform(&to_string) + ".", m->pstate());
413+
error("Duplicate key \"" + mm->get_duplicate_key()->perform(&to_string) + "\" in map " + mm->perform(&to_string) + ".", mm->pstate());
406414
}
407415

408416
mm->is_expanded(true);
@@ -927,6 +935,7 @@ namespace Sass {
927935
} else if (str->quote_mark()) {
928936
str->quote_mark('*');
929937
}
938+
str->is_delayed(true);
930939
return str;
931940
}
932941

parser.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,12 +1105,6 @@ namespace Sass {
11051105
(*map) << make_pair(key, value);
11061106
}
11071107

1108-
// Check was moved to eval step
1109-
// if (map->has_duplicate_key()) {
1110-
// To_String to_string(&ctx);
1111-
// error("Duplicate key \"" + map->get_duplicate_key()->perform(&to_string) + "\" in map " + map->perform(&to_string) + ".", pstate);
1112-
// }
1113-
11141108
ParserState ps = map->pstate();
11151109
ps.offset = pstate - ps + pstate.offset;
11161110
map->pstate(ps);

0 commit comments

Comments
 (0)