diff -r 4803a6d569f7 Lib/test/test_compile.py --- a/Lib/test/test_compile.py Mon Apr 27 17:49:16 2015 +0300 +++ b/Lib/test/test_compile.py Mon Apr 27 16:30:18 2015 -0400 @@ -460,6 +460,17 @@ ast.body = [_ast.BoolOp()] self.assertRaises(TypeError, compile, ast, '', 'exec') + def test_dict_compile_order(self): + i = 0 + + def f(): + nonlocal i + i += 1 + return i + + d = {f(): f(), f(): f()} + self.assertEqual(d, {1: 2, 3: 4}) + @support.cpython_only def test_same_filename_used(self): s = """def f(): pass\ndef g(): pass""" diff -r 4803a6d569f7 Python/ceval.c --- a/Python/ceval.c Mon Apr 27 17:49:16 2015 +0300 +++ b/Python/ceval.c Mon Apr 27 16:30:18 2015 -0400 @@ -2407,8 +2407,8 @@ } TARGET(STORE_MAP) { - PyObject *key = TOP(); - PyObject *value = SECOND(); + PyObject *value = TOP(); + PyObject *key = SECOND(); PyObject *map = THIRD(); int err; STACKADJ(-2); diff -r 4803a6d569f7 Python/compile.c --- a/Python/compile.c Mon Apr 27 17:49:16 2015 +0300 +++ b/Python/compile.c Mon Apr 27 16:30:18 2015 -0400 @@ -3434,9 +3434,9 @@ ADDOP_I(c, BUILD_MAP, (n>0xFFFF ? 0xFFFF : n)); for (i = 0; i < n; i++) { VISIT(c, expr, + (expr_ty)asdl_seq_GET(e->v.Dict.keys, i)); + VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Dict.values, i)); - VISIT(c, expr, - (expr_ty)asdl_seq_GET(e->v.Dict.keys, i)); ADDOP(c, STORE_MAP); } break;