Permalink
Browse files

Fixed bug in CSharpAstResolver.GetExpectedType().

  • Loading branch information...
1 parent f74bf90 commit e80f14238191aaace87932760d3640f22ace42d5 @dgrunwald dgrunwald committed Mar 15, 2012
@@ -452,20 +452,6 @@ public ResolveResult GetResolveResult(AstNode node)
return null;
}
- /// <summary>
- /// Gets the resolve result for the specified node.
- /// If the node was not resolved by the navigator, this method will return null.
- /// </summary>
- public ResolveResult GetResolveResultIfResolved(AstNode node)
- {
- MergeUndecidedLambdas();
- ResolveResult result;
- if (resolveResultCache.TryGetValue(node, out result))
- return result;
- else
- return null;
- }
-
CSharpResolver GetPreviouslyScannedContext(AstNode node, out AstNode parent)
{
parent = node;
@@ -530,7 +516,7 @@ public ConversionWithTargetType GetConversionWithTargetType(Expression expr)
if (conversionDict.TryGetValue(expr, out result)) {
return result;
} else {
- ResolveResult rr = GetResolveResultIfResolved(expr);
+ ResolveResult rr = GetResolveResult(expr);
return new ConversionWithTargetType(Conversion.IdentityConversion, rr != null ? rr.Type : SpecialType.UnknownType);
}
}
@@ -2515,7 +2501,7 @@ ResolveResult IAstVisitor<ResolveResult>.VisitForeachStatement(ForeachStatement
resolver = resolver.PushBlock();
IVariable v;
- if (IsVar(foreachStatement.VariableType)) {
+ if (isImplicitlyTypedVariable) {
StoreCurrentState(foreachStatement.VariableType);
StoreResult(foreachStatement.VariableType, new TypeResolveResult(elementType));
v = MakeVariable(elementType, foreachStatement.VariableNameToken);
@@ -54,6 +54,8 @@ public static void RunTest(CSharpFile file)
bool checkResults = rnd.Next(0, 2) == 0;
bool checkStateBefore = rnd.Next(0, 2) == 0;
bool checkStateAfter = rnd.Next(0, 2) == 0;
+ bool checkConversion = rnd.Next(0, 2) == 0;
+ bool checkExpectedType = rnd.Next(0, 2) == 0;
foreach (var _node in file.CompilationUnit.DescendantsAndSelf) {
var node = _node;
if (CSharpAstResolver.IsUnresolvableNode(node))
@@ -66,8 +68,10 @@ public static void RunTest(CSharpFile file)
actions.Add(() => test.CheckStateAfter(node));
var expr = node as Expression;
if (expr != null) {
- //actions.Add(() => test.CheckExpectedType(node));
- //actions.Add(() => test.CheckConversion(node));
+ if (checkConversion)
+ actions.Add(() => test.CheckConversion(expr));
+ if (checkExpectedType)
+ actions.Add(() => test.CheckExpectedType(expr));
}
}
@@ -119,6 +123,30 @@ bool CheckStateAfter(AstNode node)
return false;
}
+ bool CheckConversion(Expression node)
+ {
+ Conversion expectedConversion = resolveAllResolver.GetConversion(node);
+ Conversion actualConversion = resolver.GetConversion(node);
+ if (Compare(expectedConversion, actualConversion, typeof(Conversion)))
+ return true;
+ Console.WriteLine("Different conversions for '{0}' at {1} in {2}:", node, node.StartLocation, node.GetRegion().FileName);
+ Console.WriteLine(" expected: " + expectedConversion);
+ Console.WriteLine(" actual: " + actualConversion);
+ return false;
+ }
+
+ bool CheckExpectedType(Expression node)
+ {
+ IType expectedExpectedType = resolveAllResolver.GetExpectedType(node);
+ IType actualExpectedType = resolver.GetExpectedType(node);
+ if (expectedExpectedType.Equals(actualExpectedType))
+ return true;
+ Console.WriteLine("Different expected types for '{0}' at {1} in {2}:", node, node.StartLocation, node.GetRegion().FileName);
+ Console.WriteLine(" expected: " + expectedExpectedType);
+ Console.WriteLine(" actual: " + actualExpectedType);
+ return false;
+ }
+
bool IsEqualResolveResult(ResolveResult rr1, ResolveResult rr2)
{
if (rr1 == rr2)

0 comments on commit e80f142

Please sign in to comment.