Browse Source

fix bug in ExpressionEvaluationVisitor: comparison of two enum values was not possible

pull/517/head
Siegfried Pammer 11 years ago
parent
commit
910cbf4148
  1. 8
      src/AddIns/Debugger/Debugger.AddIn/NRefactory/ExpressionEvaluationVisitor.cs
  2. 7
      src/AddIns/Debugger/Debugger.Core/Eval.cs
  3. 10
      src/AddIns/Debugger/Debugger.Core/Value.cs

8
src/AddIns/Debugger/Debugger.AddIn/NRefactory/ExpressionEvaluationVisitor.cs

@ -114,8 +114,12 @@ namespace Debugger.AddIn @@ -114,8 +114,12 @@ namespace Debugger.AddIn
public Value Convert(ResolveResult result)
{
if (result.IsCompileTimeConstant && !result.IsError)
return Eval.CreateValue(evalThread, result.ConstantValue);
if (result.IsCompileTimeConstant && !result.IsError) {
var type = Import(result.Type);
if (type == null)
throw new GetValueException("Error: cannot find '{0}'.", result.Type.FullName);
return Eval.CreateValue(evalThread, result.ConstantValue, type);
}
return Visit((dynamic)result);
}

7
src/AddIns/Debugger/Debugger.Core/Eval.cs

@ -268,7 +268,7 @@ namespace Debugger @@ -268,7 +268,7 @@ namespace Debugger
);
}
public static Value CreateValue(Thread evalThread, object value)
public static Value CreateValue(Thread evalThread, object value, IType type = null)
{
if (value == null) {
ICorDebugClass corClass = evalThread.AppDomain.ObjectType.ToCorDebug().GetClass();
@ -278,9 +278,10 @@ namespace Debugger @@ -278,9 +278,10 @@ namespace Debugger
} else if (value is string) {
return Eval.NewString(evalThread, (string)value);
} else {
if (!value.GetType().IsPrimitive)
if (type == null)
type = evalThread.AppDomain.Compilation.FindType(value.GetType());
if (!type.IsPrimitiveType() && type.Kind != TypeKind.Enum)
throw new DebuggerException("Value must be primitve type. Seen " + value.GetType());
IType type = evalThread.AppDomain.Compilation.FindType(value.GetType());
Value val = Eval.NewObjectNoConstructor(evalThread, type);
val.SetPrimitiveValue(evalThread, value);
return val;

10
src/AddIns/Debugger/Debugger.Core/Value.cs

@ -319,11 +319,17 @@ namespace Debugger @@ -319,11 +319,17 @@ namespace Debugger
if (this.Type.IsKnownType(KnownTypeCode.String)) {
this.SetValue(evalThread, Eval.NewString(evalThread, value.ToString()));
} else {
if (!this.Type.IsPrimitiveType())
if (!Type.IsPrimitiveType() && Type.Kind != TypeKind.Enum)
throw new DebuggerException("Value is not a primitive type");
if (value == null)
throw new DebuggerException("Can not set primitive value to null");
CorGenericValue.SetValue(this.Type.GetDefinition().KnownTypeCode, value);
KnownTypeCode knownTypeCode;
var typeDefinition = this.Type.GetDefinition();
if (this.Type.Kind == TypeKind.Enum)
knownTypeCode = typeDefinition.EnumUnderlyingType.GetDefinition().KnownTypeCode;
else
knownTypeCode = typeDefinition.KnownTypeCode;
CorGenericValue.SetValue(knownTypeCode, value);
}
}

Loading…
Cancel
Save