Git Product home page Git Product logo

Comments (8)

7sharp9 avatar 7sharp9 commented on May 28, 2024

@kevmal This looks familiar to that one you fixed in Enum a while back, can you remember what was causing it? A cast from object or something like that?

from falanx.

7sharp9 avatar 7sharp9 commented on May 28, 2024

Think Ive found it...

from falanx.

kevmal avatar kevmal commented on May 28, 2024

Seems like two issues here. First problem is that typeof<obj>.IsAssignableFrom(--provided type--) always returns false resulting in a downcast here:

| Coerce(e, t) ->
//dependencies.Append t
let synExpr = exprToAst e
let synType = sysTypeToSynType range t knownNamespaces ommitEnclosingType
let synCoerce =
// Need to manually check for interface. <interface>.IsAssignableFrom(<provided_type :> interface>) does not properly return true
if (t.IsInterface && (Array.contains t (e.Type.GetInterfaces()))) || t.IsAssignableFrom e.Type then
SynExpr.Upcast(synExpr, synType, range)
else
SynExpr.Downcast(synExpr, synType, range)

Second issue is with the referenced version of fantomas, this fails

Fantomas.CodeFormatter.FormatDocument("bleh.fsx", "let a = 1 :> obj",Fantomas.FormatConfig.FormatConfig.Default)

with System.InvalidCastException: Unable to cast object of type 'Upcast' to type 'Downcast'..

Luckily it seems like testing with fantomas master this may be fixed.

from falanx.

7sharp9 avatar 7sharp9 commented on May 28, 2024

I dropped all the box operations and coercions to obj and it seems to work, not got to upgrading Fantomas yet...

from falanx.

7sharp9 avatar 7sharp9 commented on May 28, 2024

So we also need to fix | Coerce(e, t) with special consideration for ProvidedTypes.

from falanx.

7sharp9 avatar 7sharp9 commented on May 28, 2024

@kevmal So on a ProvidedType instance maybe Utils.isAssignableFrom could work

from falanx.

kevmal avatar kevmal commented on May 28, 2024

Seems like Utils.isAssignableFrom just reduces to the same call.

        let isAssignableFrom (ty: Type) (otherTy: Type) =
            eqTypes ty otherTy || (match otherTy.BaseType with null -> false | bt -> ty.IsAssignableFrom(bt))

from falanx.

7sharp9 avatar 7sharp9 commented on May 28, 2024

Fixed by #73

from falanx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.