Zewo / Reflection

DEPRECATED
MIT License
599 stars 46 forks source link

Fix for setting value on a class object thats casted as an Any #7

Closed wickwirew closed 7 years ago

wickwirew commented 7 years ago

I ran into an issue setting a value on an object that was casted as an Any. From what I can tell the problem was in the storage. The type of the instance was not being recognized as AnyClass even though it is. What is happening is once it is passed to storage<T> casted as an Any the method type(of:) no longer returns the correct type of the instance, it returns Any due to the generics. Would like to hear your input.

Not sure if this is the best way to fix it. Another solution would be to remove the generics but that may break other things. This is less invasive

wickwirew commented 7 years ago

Heres an example of the original issue. Without the Any it works

class TestClass {
    var value: Int = 0
}

var instance: Any = TestClass()
try? set(35, key: "value", for: &instance)
print((instance as! TestClass).value) // Prints 0
codecov-io commented 7 years ago

Codecov Report

Merging #7 into master will decrease coverage by <.01%. The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
- Coverage   80.38%   80.38%   -0.01%     
==========================================
  Files          27       27              
  Lines         566      571       +5     
==========================================
+ Hits          455      459       +4     
- Misses        111      112       +1
Impacted Files Coverage Δ
Sources/Reflection/Set.swift 45.45% <0%> (-4.55%) :arrow_down:
Sources/Reflection/Storage.swift 87.5% <100%> (+4.16%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9400cd8...d1f70b7. Read the comment docs.

paulofaria commented 7 years ago

@bradhilton did you take a look at this? (:

iby commented 7 years ago

@bradhilton any chance this can be reviewed and merged?

iby commented 7 years ago

By the way, I believe this should fix https://github.com/Zewo/Zewo/issues/237 and possibly https://github.com/Zewo/Zewo/issues/238.