Commit 21ad2151 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 c48d7bb7
......@@ -2,6 +2,16 @@
Cython Changelog
================
0.28.6 (??)
===================
Bugs fixed
----------
* Multiplied string literals lost their factor when they are part of another
constant expression (e.g. 'x' * 10 + 'y' => 'xy').
0.28.5 (2018-08-03)
===================
......
......@@ -4234,7 +4234,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