Commit 04b4af1a authored by Stefan Behnel's avatar Stefan Behnel

Fix constant folding of multiplied string literals when they appear in another...

Fix constant folding of multiplied string literals when they appear in another constant expression. In this case, the multiplied value was lost and replaced by the original value.
parent f570811e
......@@ -67,6 +67,9 @@ Bugs fixed
* 2-value slicing of typed sequences failed if the start or stop index was None.
Patch by Christian Gibson. (Github issue #2508)
* Multiplied string literals lost their factor when they are part of another
constant expression (e.g. 'x' * 10 + 'y' => 'xy').
* The directive ``language_level=3`` did not apply to the first token in the
source file. (Github issue #2230)
......
......@@ -4247,7 +4247,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
string_node.bytes_value.encoding)
else:
assert False, "unknown string node type: %s" % type(string_node)
string_node.value = build_string(
string_node.constant_result = string_node.value = build_string(
string_node.value * multiplier,
string_node.value.encoding)
return string_node
......
......@@ -85,6 +85,8 @@ __doc__ = br"""
True
>>> wide_literal == u'\\U00101234' # unescaped by Python
True
>>> ustring_in_constant_tuple == ('a', u'abc', u'\\N{SNOWMAN}', u'x' * 3, u'\\N{SNOWMAN}' * 4 + u'O') or ustring_in_constant_tuple # unescaped by Python
True
"""
if sys.version_info >= (2,6,5):
......@@ -118,3 +120,5 @@ add = u'Søk ik' + u'üÖä' + u'abc'
null = u'\x00'
wide_literal = u'\U00101234'
ustring_in_constant_tuple = ('a', u'abc', u'\N{SNOWMAN}', u'x' * 3, u'\N{SNOWMAN}' * 4 + u'O')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment