Skip to content

Commit 9f22865

Browse files
authored
Add nullable annotations (#967)
1 parent 58b3bda commit 9f22865

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

Src/IronPython/Compiler/Ast/AndExpression.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
using MSAst = System.Linq.Expressions;
5+
#nullable enable
66

77
using System;
8-
using IronPython.Runtime.Binding;
98
using Microsoft.Scripting.Actions;
109
using Microsoft.Scripting.Utils;
11-
using AstUtils = Microsoft.Scripting.Ast.Utils;
1210

1311
namespace IronPython.Compiler.Ast {
14-
using Ast = MSAst.Expression;
12+
using Ast = System.Linq.Expressions.Expression;
13+
using AstUtils = Microsoft.Scripting.Ast.Utils;
1514

1615
public class AndExpression : Expression {
1716
public AndExpression(Expression left, Expression right) {
@@ -28,15 +27,15 @@ public AndExpression(Expression left, Expression right) {
2827

2928
public Expression Right { get; }
3029

31-
public override MSAst.Expression Reduce() {
32-
MSAst.Expression left = Left;
33-
MSAst.Expression right = Right;
30+
public override Ast Reduce() {
31+
var left = Left;
32+
var right = Right;
3433

3534
Type t = Type;
36-
MSAst.ParameterExpression tmp = Ast.Variable(t, "__all__");
35+
var tmp = Variable(t, "__all__");
3736

3837
return Block(
39-
new [] { tmp },
38+
new[] { tmp },
4039
Condition(
4140
GlobalParent.Convert(
4241
typeof(bool),
@@ -60,7 +59,8 @@ public override MSAst.Expression Reduce() {
6059

6160
public override Type Type {
6261
get {
63-
return Left.Type == Right.Type ? Left.Type : typeof(object);
62+
Type leftType = Left.Type;
63+
return leftType == Right.Type ? leftType : typeof(object);
6464
}
6565
}
6666

@@ -72,10 +72,6 @@ public override void Walk(PythonWalker walker) {
7272
walker.PostWalk(this);
7373
}
7474

75-
internal override bool CanThrow {
76-
get {
77-
return Left.CanThrow || Right.CanThrow;
78-
}
79-
}
75+
internal override bool CanThrow => Left.CanThrow || Right.CanThrow;
8076
}
8177
}

Src/IronPython/Compiler/Ast/OrExpression.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
using MSAst = System.Linq.Expressions;
5+
#nullable enable
66

77
using System;
8-
using IronPython.Runtime.Binding;
98
using Microsoft.Scripting.Actions;
109
using Microsoft.Scripting.Utils;
1110

1211
namespace IronPython.Compiler.Ast {
13-
using Ast = MSAst.Expression;
12+
using Ast = System.Linq.Expressions.Expression;
1413
using AstUtils = Microsoft.Scripting.Ast.Utils;
1514

1615
public class OrExpression : Expression {
@@ -25,22 +24,23 @@ public OrExpression(Expression left, Expression right) {
2524
}
2625

2726
public Expression Left { get; }
27+
2828
public Expression Right { get; }
2929

30-
public override MSAst.Expression Reduce() {
31-
MSAst.Expression left = Left;
32-
MSAst.Expression right = Right;
30+
public override Ast Reduce() {
31+
var left = Left;
32+
var right = Right;
3333

3434
Type t = Type;
35-
MSAst.ParameterExpression tmp = Ast.Variable(t, "__all__");
35+
var tmp = Variable(t, "__all__");
3636

37-
return Ast.Block(
37+
return Block(
3838
new[] { tmp },
39-
Ast.Condition(
39+
Condition(
4040
GlobalParent.Convert(
4141
typeof(bool),
4242
ConversionResultKind.ExplicitCast,
43-
Ast.Assign(
43+
Assign(
4444
tmp,
4545
AstUtils.Convert(
4646
left,

0 commit comments

Comments
 (0)