|
218 | 218 | import com.oracle.graal.python.nodes.object.GetClassNode; |
219 | 219 | import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode; |
220 | 220 | import com.oracle.graal.python.nodes.object.IsNode; |
| 221 | +import com.oracle.graal.python.nodes.util.CannotCastException; |
| 222 | +import com.oracle.graal.python.nodes.util.CastToTruffleStringNode; |
221 | 223 | import com.oracle.graal.python.nodes.util.ExceptionStateNodes; |
222 | 224 | import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext; |
223 | 225 | import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; |
@@ -3203,12 +3205,22 @@ public static final class BuildString { |
3203 | 3205 | public static Object perform( |
3204 | 3206 | int length, |
3205 | 3207 | @Variadic Object[] strings, |
| 3208 | + @Bind Node inliningTarget, |
| 3209 | + @Cached CastToTruffleStringNode castToStringNode, |
3206 | 3210 | @Cached TruffleStringBuilder.AppendStringNode appendNode, |
3207 | | - @Cached TruffleStringBuilder.ToStringNode toString) { |
| 3211 | + @Cached TruffleStringBuilder.ToStringNode toString, |
| 3212 | + @Cached PRaiseNode raise) { |
3208 | 3213 | var tsb = TruffleStringBuilderUTF32.create(PythonUtils.TS_ENCODING); |
3209 | 3214 | CompilerAsserts.partialEvaluationConstant(length); |
3210 | 3215 | for (int i = 0; i < length; i++) { |
3211 | | - appendNode.execute(tsb, (TruffleString) strings[i]); |
| 3216 | + try { |
| 3217 | + appendNode.execute(tsb, castToStringNode.execute(inliningTarget, strings[i])); |
| 3218 | + } catch (CannotCastException ex) { |
| 3219 | + // Python should only permit str literals or calls to `format` builtin as |
| 3220 | + // argument to this operation. The `format` builtin already ensures the result |
| 3221 | + // is a Python string. |
| 3222 | + throw CompilerDirectives.shouldNotReachHere(ex); |
| 3223 | + } |
3212 | 3224 | } |
3213 | 3225 | return toString.execute(tsb); |
3214 | 3226 | } |
|
0 commit comments