-
Notifications
You must be signed in to change notification settings - Fork 55
Type comparison operators #420
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,7 +174,10 @@ object EvaluateBinaryExpression(BinaryExpressionAst binaryExpressionAst) | |
var right = LanguagePrimitives.ConvertTo<object[]>(rightOperand); | ||
return string.Format(left, right); | ||
} | ||
|
||
case TokenKind.Is: | ||
return IsInstanceOfType(leftOperand, rightOperand); | ||
case TokenKind.IsNot: | ||
return !IsInstanceOfType(leftOperand, rightOperand); | ||
case TokenKind.Equals: | ||
case TokenKind.PlusEquals: | ||
case TokenKind.MinusEquals: | ||
|
@@ -200,8 +203,6 @@ object EvaluateBinaryExpression(BinaryExpressionAst binaryExpressionAst) | |
case TokenKind.Cin: | ||
case TokenKind.Cnotin: | ||
case TokenKind.Csplit: | ||
case TokenKind.Is: | ||
case TokenKind.IsNot: | ||
case TokenKind.As: | ||
case TokenKind.Shl: | ||
case TokenKind.Shr: | ||
|
@@ -212,6 +213,17 @@ object EvaluateBinaryExpression(BinaryExpressionAst binaryExpressionAst) | |
} | ||
} | ||
|
||
private static bool IsInstanceOfType(object leftOperand, object rightOperand) | ||
{ | ||
var type = rightOperand as Type; | ||
if (type == null) | ||
{ | ||
throw new InvalidOperationException(@"The right operand of '-is' must be a type."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a verbatim string literal here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To emphasise localisable text only literal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ygra, I think that some tools such as Resharper will throw a warning here mentioning "possibly localizable string". Making a literal verbatim is really a way to suppress this warning. So: a) I don't think we generally use this practice in Pash code So I don't think that you should use verbatim string literal here. Better get rid of that. |
||
} | ||
|
||
return type.IsInstanceOfType(leftOperand); | ||
} | ||
|
||
private bool Match(object leftOperand, object rightOperand, RegexOptions regexOptions) | ||
{ | ||
if (!(leftOperand is string) || !(rightOperand is string)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The right operand is coerced to a type, actually.
I think
LanguagePrimitives.ConvertTo
should take care of that.And the right operand can be an expression:
Not sure right now whether that's already covered here.
Granted, we don't have to fix those in the first iteration, but we should keep it in mind.