Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE changes for "Unsigned Right Shift" feature, plus tests. #60689

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public enum SyntaxKind : ushort
/// <summary>Represents <c>&gt;&gt;&gt;=</c> token.</summary>
GreaterThanGreaterThanGreaterThanEqualsToken = 8287,

// When adding punctuation, the following functions must be adapted:
// <see cref="SyntaxFacts.IsPunctuation"/>
// <see cref="SyntaxFacts.GetPunctuationKinds"/>

// Keywords
/// <summary>Represents <see langword="bool"/>.</summary>
BoolKeyword = 8304,
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Syntax/SyntaxKindFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static IEnumerable<SyntaxKind> GetPreprocessorKeywordKinds()

public static bool IsPunctuation(SyntaxKind kind)
{
return kind >= SyntaxKind.TildeToken && kind <= SyntaxKind.QuestionQuestionEqualsToken;
return kind >= SyntaxKind.TildeToken && kind <= SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken;
Copy link
Member

@jasonmalinowski jasonmalinowski Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also including !! that wasn't included before; that seems reasonable to me but we think that was just an oversight before? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also including !! that wasn't included before; that seems reasonable to me but we think that was just an oversight before?

I think it was. CC @RikkiGibson

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was an oversight. It looks like this could change behavior of classification of !!, but I must not have added any tests for !! to src/EditorFeatures/CSharpTest/Classification/SyntacticClassifierTests.cs.

}

public static bool IsLanguagePunctuation(SyntaxKind kind)
Expand All @@ -164,7 +164,7 @@ private static bool IsDebuggerSpecialPunctuation(SyntaxKind kind)

public static IEnumerable<SyntaxKind> GetPunctuationKinds()
{
for (int i = (int)SyntaxKind.TildeToken; i <= (int)SyntaxKind.PercentEqualsToken; i++)
for (int i = (int)SyntaxKind.TildeToken; i <= (int)SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken; i++)
Copy link
Member

@jasonmalinowski jasonmalinowski Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a test that each kind returned from GetPunctuationKinds returns true for IsPunctuationKind? Since it seems there were other existing bugs here too. #Resolved

{
yield return (SyntaxKind)i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5203,6 +5203,7 @@ public void BinaryComparisonCastToVoidStar_NoWarning(string @operator)
[InlineData("%")]
[InlineData("<<")]
[InlineData(">>")]
[InlineData(">>>")]
[InlineData("&&")]
[InlineData("||")]
[InlineData("&")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3370,6 +3370,7 @@ static void Main()
var q = new() && new();
var r = new() || new();
var s = new() ?? new();
var t = new() >>> new();
}
}
";
Expand Down Expand Up @@ -3438,7 +3439,10 @@ static void Main()
Diagnostic(ErrorCode.ERR_ImplicitObjectCreationNoTargetType, "new()").WithArguments("new()").WithLocation(23, 26),
// (24,17): error CS8754: There is no target type for 'new()'
// var s = new() ?? new();
Diagnostic(ErrorCode.ERR_ImplicitObjectCreationNoTargetType, "new()").WithArguments("new()").WithLocation(24, 17)
Diagnostic(ErrorCode.ERR_ImplicitObjectCreationNoTargetType, "new()").WithArguments("new()").WithLocation(24, 17),
// (25,17): error CS8310: Operator '>>>' cannot be applied to operand 'new()'
// var t = new() >>> new();
Diagnostic(ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, "new() >>> new()").WithArguments(">>>", "new()").WithLocation(25, 17)
);
}

Expand Down Expand Up @@ -3469,6 +3473,7 @@ static void Main()
_ = new() && 1;
_ = new() || 1;
_ = new() ?? 1;
_ = new() >>> 1;
}
}
";
Expand Down Expand Up @@ -3531,7 +3536,10 @@ static void Main()
Diagnostic(ErrorCode.ERR_ImplicitObjectCreationNoTargetType, "new()").WithArguments("new()").WithLocation(23, 13),
// (24,13): error CS8754: There is no target type for 'new()'
// _ = new() ?? 1;
Diagnostic(ErrorCode.ERR_ImplicitObjectCreationNoTargetType, "new()").WithArguments("new()").WithLocation(24, 13)
Diagnostic(ErrorCode.ERR_ImplicitObjectCreationNoTargetType, "new()").WithArguments("new()").WithLocation(24, 13),
// (25,13): error CS8310: Operator '>>>' cannot be applied to operand 'new()'
// _ = new() >>> 1;
Diagnostic(ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, "new() >>> 1").WithArguments(">>>", "new()").WithLocation(25, 13)
);
}

Expand Down Expand Up @@ -3562,6 +3570,7 @@ static void Main()
_ = 1 && new();
_ = 1 || new();
_ = 1 ?? new();
_ = 1 >>> new();
}
}
";
Expand Down Expand Up @@ -3624,7 +3633,10 @@ static void Main()
Diagnostic(ErrorCode.ERR_ImplicitObjectCreationNoTargetType, "new()").WithArguments("new()").WithLocation(23, 18),
// (24,13): error CS0019: Operator '??' cannot be applied to operands of type 'int' and 'new()'
// _ = 1 ?? new();
Diagnostic(ErrorCode.ERR_BadBinaryOps, "1 ?? new()").WithArguments("??", "int", "new()").WithLocation(24, 13)
Diagnostic(ErrorCode.ERR_BadBinaryOps, "1 ?? new()").WithArguments("??", "int", "new()").WithLocation(24, 13),
// (25,13): error CS8310: Operator '>>>' cannot be applied to operand 'new()'
// _ = 1 >>> new();
Diagnostic(ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, "1 >>> new()").WithArguments(">>>", "new()").WithLocation(25, 13)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ public void TestLiftedBuiltInBinaryArithmetic()
{ "/", "divide" },
{ "%", "remainder" },
{ ">>", "rshift" },
{ ">>>", "urshift" },
{ "<<", "lshift" },
{ "&", "and" },
{ "|", "or" },
Expand Down Expand Up @@ -1280,6 +1281,7 @@ static void METHOD_TYPEX_NAME_TYPEY()
// UNDONE: so this test is disabled:
// UNDONE: Tuple.Create("-", enumSubtraction),
Tuple.Create(">>", shift1),
Tuple.Create(">>>", shift1),
Tuple.Create("<<", shift2),
Tuple.Create("&", logical1),
Tuple.Create("|", logical2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,7 @@ public void TestOperatorOverloadResolution()
TestOperatorKinds(GenerateTest(ArithmeticTemplate, "%", "Remainder"));
TestOperatorKinds(GenerateTest(ShiftTemplate, "<<", "LeftShift"));
TestOperatorKinds(GenerateTest(ShiftTemplate, ">>", "RightShift"));
TestOperatorKinds(GenerateTest(ShiftTemplate, ">>>", "UnsignedRightShift"));
TestOperatorKinds(GenerateTest(ArithmeticTemplate, "==", "Equal"));
TestOperatorKinds(GenerateTest(ArithmeticTemplate, "!=", "NotEqual"));
TestOperatorKinds(GenerateTest(EqualityTemplate, "!=", "NotEqual"));
Expand Down Expand Up @@ -6756,7 +6757,7 @@ class op_RightShift
}
class op_UnsignedRightShift
{
public static long operator >>> (op_UnsignedRightShift c, int i) { return 0; }
}
";
CreateCompilation(source).VerifyDiagnostics(
Expand Down Expand Up @@ -6804,7 +6805,11 @@ class op_UnsignedRightShift
Diagnostic(ErrorCode.ERR_MemberNameSameAsType, "<<").WithArguments("op_LeftShift"),
// (60,30): error CS0542: 'op_RightShift': member names cannot be the same as their enclosing type
// public static long operator >> (op_RightShift c, int i) { return 0; }
Diagnostic(ErrorCode.ERR_MemberNameSameAsType, ">>").WithArguments("op_RightShift"));
Diagnostic(ErrorCode.ERR_MemberNameSameAsType, ">>").WithArguments("op_RightShift"),
// (64,30): error CS0542: 'op_UnsignedRightShift': member names cannot be the same as their enclosing type
// public static long operator >>> (op_UnsignedRightShift c, int i) { return 0; }
Diagnostic(ErrorCode.ERR_MemberNameSameAsType, ">>>").WithArguments("op_UnsignedRightShift").WithLocation(64, 30)
);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ static void Main()
var q = default && default;
var r = default || default;
var s = default ?? default;
var t = default >>> default;
}
}
";
Expand Down Expand Up @@ -1348,7 +1349,10 @@ static void Main()
Diagnostic(ErrorCode.ERR_DefaultLiteralNoTargetType, "default").WithLocation(23, 28),
// (24,17): error CS8716: There is no target type for the default literal.
// var s = default ?? default;
Diagnostic(ErrorCode.ERR_DefaultLiteralNoTargetType, "default").WithLocation(24, 17)
Diagnostic(ErrorCode.ERR_DefaultLiteralNoTargetType, "default").WithLocation(24, 17),
// (25,17): error CS8310: Operator '>>>' cannot be applied to operand 'default'
// var t = default >>> default;
Diagnostic(ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, "default >>> default").WithArguments(">>>", "default").WithLocation(25, 17)
};

var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_1);
Expand Down Expand Up @@ -1386,6 +1390,7 @@ static void Main()
var r = default || 1;
var s = default ?? 1;
var t = default ?? default(int?);
var u = default >>> 1;
}
}
";
Expand Down Expand Up @@ -1450,7 +1455,10 @@ static void Main()
Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "o").WithArguments("o").WithLocation(20, 13),
// (21,13): warning CS0219: The variable 'p' is assigned but its value is never used
// var p = default != 1; // ok
Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "p").WithArguments("p").WithLocation(21, 13)
Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "p").WithArguments("p").WithLocation(21, 13),
// (26,17): error CS8310: Operator '>>>' cannot be applied to operand 'default'
// var u = default >>> 1;
Diagnostic(ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, "default >>> 1").WithArguments(">>>", "default").WithLocation(26, 17)
};

var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_1);
Expand Down Expand Up @@ -1488,6 +1496,7 @@ static void Main()
var r = 1 || default;
var s = new object() ?? default; // ok
var t = 1 ?? default;
var u = 1 >>> default;
}
}
";
Expand Down Expand Up @@ -1549,7 +1558,10 @@ static void Main()
Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "o").WithArguments("o").WithLocation(20, 13),
// (21,13): warning CS0219: The variable 'p' is assigned but its value is never used
// var p = 1 != default; // ok
Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "p").WithArguments("p").WithLocation(21, 13)
Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "p").WithArguments("p").WithLocation(21, 13),
// (26,17): error CS8310: Operator '>>>' cannot be applied to operand 'default'
// var u = 1 >>> default;
Diagnostic(ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, "1 >>> default").WithArguments(">>>", "default").WithLocation(26, 17)
};

var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_1);
Expand Down
11 changes: 10 additions & 1 deletion src/Compilers/CSharp/Test/Semantic/Semantics/UnsafeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5961,6 +5961,8 @@ void M(byte* p, int i)
var r14 = i | p;
var r15 = p ^ i;
var r16 = i ^ p;
var r17 = p >>> i;
var r18 = i >>> p;
}
}
";
Expand Down Expand Up @@ -6013,7 +6015,14 @@ void M(byte* p, int i)
Diagnostic(ErrorCode.ERR_BadBinaryOps, "p ^ i").WithArguments("^", "byte*", "int"),
// (21,19): error CS0019: Operator '^' cannot be applied to operands of type 'int' and 'byte*'
// var r16 = i ^ p;
Diagnostic(ErrorCode.ERR_BadBinaryOps, "i ^ p").WithArguments("^", "int", "byte*"));
Diagnostic(ErrorCode.ERR_BadBinaryOps, "i ^ p").WithArguments("^", "int", "byte*"),
// (22,19): error CS0019: Operator '>>>' cannot be applied to operands of type 'byte*' and 'int'
// var r17 = p >>> i;
Diagnostic(ErrorCode.ERR_BadBinaryOps, "p >>> i").WithArguments(">>>", "byte*", "int").WithLocation(22, 19),
// (23,19): error CS0019: Operator '>>>' cannot be applied to operands of type 'int' and 'byte*'
// var r18 = i >>> p;
Diagnostic(ErrorCode.ERR_BadBinaryOps, "i >>> p").WithArguments(">>>", "int", "byte*").WithLocation(23, 19)
);
}

[Fact]
Expand Down
Loading