Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The generator fail on maps where the value is a message #62

Closed
vbfox opened this issue Nov 7, 2018 · 8 comments
Closed

The generator fail on maps where the value is a message #62

vbfox opened this issue Nov 7, 2018 · 8 comments
Labels
bug Something isn't working

Comments

@vbfox
Copy link
Contributor

vbfox commented Nov 7, 2018

To Reproduce
Steps to reproduce the behavior:

  1. Run the tool on this proto file :
    syntax = "proto3";
    
    message SomeMessage {
        int64 id = 1;
    }
    
    message SomeMessageWithMap {
        map<string, SomeMessage> some_map = 1;
    }
  2. See the Unable to cast object of type 'Downcast' to type 'InferredUpcast'. error.

Additional context

Tested on master

@7sharp9 7sharp9 added the bug Something isn't working label Nov 26, 2018
@7sharp9
Copy link
Contributor

7sharp9 commented Nov 26, 2018

@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?

@7sharp9
Copy link
Contributor

7sharp9 commented Nov 26, 2018

Think Ive found it...

@kevmal
Copy link
Contributor

kevmal commented Nov 26, 2018

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.

@7sharp9
Copy link
Contributor

7sharp9 commented Nov 26, 2018

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

@7sharp9
Copy link
Contributor

7sharp9 commented Nov 26, 2018

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

@7sharp9
Copy link
Contributor

7sharp9 commented Nov 26, 2018

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

@kevmal
Copy link
Contributor

kevmal commented Nov 26, 2018

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))

@7sharp9
Copy link
Contributor

7sharp9 commented Nov 28, 2018

Fixed by #73

@7sharp9 7sharp9 closed this as completed Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants