Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for infinite recursive lookup. Not the best fix, but it'll do for…

… now.

Signed-off-by: Richard Minerich <richard.minerich@gmail.com>
  • Loading branch information...
commit ea6f76e9f91fc70c3146f42fc439527cb08878e3 1 parent 6fd4f88
@Rickasaurus authored
View
12 Barb.Tests/Barb.Tests.fsproj
@@ -11,10 +11,14 @@
<AssemblyName>Barb.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<Name>Barb.Tests</Name>
- <SccProjectName>SAK</SccProjectName>
- <SccProvider>SAK</SccProvider>
- <SccAuxPath>SAK</SccAuxPath>
- <SccLocalPath>SAK</SccLocalPath>
+ <SccProjectName>
+ </SccProjectName>
+ <SccProvider>
+ </SccProvider>
+ <SccAuxPath>
+ </SccAuxPath>
+ <SccLocalPath>
+ </SccLocalPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
View
10 Barb.Tests/InternalsTests.fs
@@ -25,16 +25,6 @@ let ``getCachedProperties should work on single depth lookup`` () =
Assert.Equal(2, (getProperyOrFail lookupCache "Two") testInstance :?> int)
[<Fact>]
-let ``getCachedProperties should work on double depth lookup`` () =
- let lookupCache = getCachedMembers typeof<testLayerTwo>
- let testSubInstance = { One = 1; Two = 2 }
- let testInstance = { LOne = testSubInstance; Name = "Hello" } :> obj
- let loneOneVal = getProperyOrFail lookupCache "LOne.One" testInstance
- Assert.Equal(1, loneOneVal :?> int)
- Assert.Equal(2, (getProperyOrFail lookupCache "LOne.Two") testInstance :?> int)
- Assert.Equal("Hello", (getProperyOrFail lookupCache "Name") testInstance :?> string)
-
-[<Fact>]
let ``tokenizeString should correctly tokenize a simple string`` () =
let tokens = tokenizeString "Hello = World"
Assert.Equal(3, tokens.Length)
View
11 Barb.Tests/LanguageTests.fs
@@ -145,4 +145,13 @@ let ``predicate language should support comparing null values`` () =
let testRecord = { Name = null; Age = 20 }
let dudePredicate = buildExpr<DudeRecordWithInt,bool> "Name = null"
let result = dudePredicate testRecord
- Assert.True(result)
+ Assert.True(result)
+
+type OptionRecord = { OptionalName: string option; Age: int }
+
+[<Fact>]
+let ``predicate language shouldn't choke on option types`` () =
+ let testRecord = { OptionalName = Some "Dude"; Age = 20 }
+ let dudePredicate = buildExpr<OptionRecord,bool> "Name = Dude"
+ let result = dudePredicate testRecord
+ Assert.True(result)
View
12 Barb.sln
@@ -6,18 +6,6 @@ EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Barb.Tests", "Barb.Tests\Barb.Tests.fsproj", "{482B4B14-7FDA-4857-8021-BA599ABEC8EB}"
EndProject
Global
- GlobalSection(TeamFoundationVersionControl) = preSolution
- SccNumberOfProjects = 3
- SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
- SccTeamFoundationServer = http://team-server:8080/tfs/bayardrock
- SccLocalPath0 = .
- SccProjectUniqueName1 = Barb\\Barb.fsproj
- SccProjectName1 = Barb
- SccLocalPath1 = Barb
- SccProjectUniqueName2 = Barb.Tests\\Barb.Tests.fsproj
- SccProjectName2 = Barb.Tests
- SccLocalPath2 = Barb.Tests
- EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
View
35 Barb/Internals.fs
@@ -35,6 +35,11 @@ type ExprTypes =
| Tuple of ExprTypes list
| ResolvedTuple of ExprTypes list
+let nullableToOption res =
+ match res with
+ | null -> None
+ | item -> Some item
+
let rec resolveMembers (rtype: System.Type) (parentName: string) (getter: obj -> obj) =
let properties = rtype.GetProperties()
let methodCollections = rtype.GetMethods()
@@ -72,9 +77,9 @@ let rec resolveMembers (rtype: System.Type) (parentName: string) (getter: obj ->
let parentResult = getter instance
prop.GetValue(parentResult, null)
yield fullName, PropertyCall getPropFunc
- yield! resolveMembers prop.PropertyType fullName getPropFunc
}
+// This is awful and needs to be rewritten I know, just a temp fix for now
let internal getCachedDelayedMembers (baseMemberCache: ConcurrentDictionary<_,_>) =
let cachedChildren = new HashSet<_>()
let memberCache = new ConcurrentDictionary<_, _>(baseMemberCache)
@@ -89,29 +94,37 @@ let internal getCachedDelayedMembers (baseMemberCache: ConcurrentDictionary<_,_>
let parentName = memberName.Substring(0, i)
let childName = memberName.Substring(i + 1, memberName.Length - 1 - i)
parentName, childName, memberCache.[parentName])
-
- let updateCacheWithNewType memberName instance =
- let parent, child, parentMember = findLowestCommonMember memberName |> Option.get
+
+ let rec updateCacheWithNewType memberName instance =
+ let parent, child, parentMember =
+ match findLowestCommonMember memberName with
+ | Some (result) -> result
+ | None -> failwith (sprintf "Base member not found: %s" memberName)
+
if not <| cachedChildren.Contains(parent) then
let parentProp =
parentMember
|> function
| PropertyCall (call) -> call
| other -> failwith (sprintf "Expected a property, but got a member while doing a dynamic lookup for: %s" memberName)
+
let childInstance = parentProp instance
+
resolveMembers (childInstance.GetType()) parent parentProp
|> Seq.iter (fun (k,v) -> memberCache.TryAdd(k,v) |> ignore)
cachedChildren.Add(parent) |> ignore
+
+ getFromCache memberName instance
else
failwith (sprintf "Delayed lookup failed on parent (%s) and child (%s), member not found in type" parent child)
- fun memberName instance ->
- let rec matchMember () =
- match memberCache.TryGetValue memberName with
- | true, foundMember -> foundMember
- | false, _ -> updateCacheWithNewType memberName instance
- matchMember ()
- matchMember()
+ and getFromCache memberName instance =
+ match memberCache.TryGetValue memberName with
+ | true, foundMember -> foundMember
+ | false, _ -> updateCacheWithNewType memberName instance
+
+ getFromCache
+
let convertToTargetType (ttype: Type) (param: obj) =
if param = null then Some null
View
BIN  tools/xunit/xunit.dll
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.