Skip to content

Commit 0818a42

Browse files
authored
Update after review (#1178)
* Updates after review * Remove EmptyArray
1 parent c6a4cb4 commit 0818a42

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

Src/IronPython/Compiler/Ast/CallExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static MSAst.Expression UnpackDictHelper(MSAst.Expression context, ReadOnlySpan<
176176
expressions.Add(Expression.Assign(varExpr, Expression.Call(AstMethods.MakeEmptyDict)));
177177
foreach (var arg in kwargs) {
178178
if (arg.Name is null) {
179-
expressions.Add(Expression.Call(AstMethods.DictMerge, context, varExpr, arg.Expression));
179+
expressions.Add(Expression.Call(AstMethods.DictMerge, context, varExpr, AstUtils.Convert(arg.Expression, typeof(object))));
180180
}
181181
}
182182
expressions.Add(varExpr);

Src/IronPython/Compiler/Ast/ClassDefinition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ static MSAst.Expression UnpackBasesHelper(ReadOnlySpan<Expression> bases) {
222222
}
223223

224224
// Compare to: CallExpression.Reduce.__UnpackDictHelper
225-
static MSAst.Expression UnpackKeywordsHelper(MSAst.Expression context, IReadOnlyList<Keyword> kwargs) {
226-
if (kwargs.Count == 0) {
225+
static MSAst.Expression UnpackKeywordsHelper(MSAst.Expression context, ReadOnlySpan<Keyword> kwargs) {
226+
if (kwargs.Length == 0) {
227227
return AstUtils.Constant(null, typeof(PythonDictionary));
228228
}
229229

230-
var expressions = new ReadOnlyCollectionBuilder<MSAst.Expression>(kwargs.Count + 2);
230+
var expressions = new ReadOnlyCollectionBuilder<MSAst.Expression>(kwargs.Length + 2);
231231
var varExpr = Expression.Variable(typeof(PythonDictionary), "$dict");
232232
expressions.Add(Expression.Assign(varExpr, Expression.Call(AstMethods.MakeEmptyDict)));
233233
foreach (var arg in kwargs) {

Src/IronPython/Compiler/Ast/Expression.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
namespace IronPython.Compiler.Ast {
2121
public abstract class Expression : Node {
22-
internal static readonly Expression[] EmptyArray = Array.Empty<Expression>();
23-
2422
protected internal static MSAst.BlockExpression UnpackSequenceHelper<T>(ReadOnlySpan<Expression> items, MethodInfo makeEmpty, MethodInfo append, MethodInfo extend) {
2523
var expressions = new ReadOnlyCollectionBuilder<MSAst.Expression>(items.Length + 2);
2624
var varExpr = Expression.Variable(typeof(T), "$coll");

Src/IronPython/Compiler/Ast/Keyword.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44

55
#nullable enable
66

7-
using Microsoft.Scripting.Actions;
7+
using System;
88

99
namespace IronPython.Compiler.Ast {
1010
public class Keyword : Node {
1111
public Keyword(string? name, Expression expression) {
1212
Name = name;
13-
Expression = expression;
13+
Expression = expression ?? throw new ArgumentNullException(nameof(expression));
1414
}
1515

1616
public string? Name { get; }
1717

1818
public Expression Expression { get; }
1919

2020
public override string ToString() {
21-
return base.ToString() + ":" + Name;
21+
return base.ToString() + ":" + (Name ?? "**{...}");
2222
}
2323

2424
public override void Walk(PythonWalker walker) {
2525
if (walker.Walk(this)) {
26-
Expression?.Walk(walker);
26+
Expression.Walk(walker);
2727
}
2828
walker.PostWalk(this);
2929
}

0 commit comments

Comments
 (0)