Browse Source

Fixed cyclic constants.

newNRvisualizers
Mike Krüger 13 years ago
parent
commit
24e7b56613
  1. 5
      ICSharpCode.NRefactory.CSharp/Resolver/CSharpConversions.cs
  2. 1
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs
  3. 23
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedField.cs

5
ICSharpCode.NRefactory.CSharp/Resolver/CSharpConversions.cs

@ -651,7 +651,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
long val = (long)rr.ConstantValue; long val = (long)rr.ConstantValue;
return val >= 0 && toTypeCode == TypeCode.UInt64; return val >= 0 && toTypeCode == TypeCode.UInt64;
} else if (fromTypeCode == TypeCode.Int32) { } else if (fromTypeCode == TypeCode.Int32) {
int val = (int)rr.ConstantValue; object cv = rr.ConstantValue;
if (cv == null)
return false;
int val = (int)cv;
switch (toTypeCode) { switch (toTypeCode) {
case TypeCode.SByte: case TypeCode.SByte:
return val >= SByte.MinValue && val <= SByte.MaxValue; return val >= SByte.MinValue && val <= SByte.MaxValue;

1
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

@ -97,6 +97,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
Assert.NotNull (testType); Assert.NotNull (testType);
var field = testType.Fields.First (); var field = testType.Fields.First ();
Assert.IsTrue (field.IsConst); Assert.IsTrue (field.IsConst);
Assert.IsNull (field.ConstantValue);
} }
} }

23
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedField.cs

@ -19,6 +19,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{ {
@ -49,16 +50,20 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public object ConstantValue { public object ConstantValue {
get { get {
ResolveResult rr = this.constantValue; using (var busyLock = BusyManager.Enter(this)) {
if (rr == null) { if (!busyLock.Success)
IConstantValue unresolvedCV = ((IUnresolvedField)unresolved).ConstantValue; return null;
if (unresolvedCV != null) ResolveResult rr = this.constantValue;
rr = unresolvedCV.Resolve(context); if (rr == null) {
else IConstantValue unresolvedCV = ((IUnresolvedField)unresolved).ConstantValue;
rr = ErrorResolveResult.UnknownError; if (unresolvedCV != null)
this.constantValue = rr; rr = unresolvedCV.Resolve(context);
else
rr = ErrorResolveResult.UnknownError;
this.constantValue = rr;
}
return rr.ConstantValue;
} }
return rr.ConstantValue;
} }
} }
} }

Loading…
Cancel
Save