Skip to content

Fail to derive Generic with record argument referenced through type synonym #1443

Description

@zudov
type MyArray   = Array String
type MyString  = String
type MyNumber  = Number
type MyInt     = Int
type MyBoolean = Boolean
type MyProduct = Maybe String
type MyRecord  = { x :: Number, y :: Number }

data Foo = Foo MyArray   -- fine
               MyString  -- fine
               MyNumber  -- fine
               MyInt     -- fine
               MyBoolean -- fine
               MyProduct -- fine
               MyRecord  -- FAIL
derive instance fooGeneric :: Generic Foo

fails with

No instance found for Data.Generic.Generic MyModule.MyRecord<>

Activity

  1. garyb commented on Aug 31, 2015

    @garyb
    Member

    I assume MyRecord was called Point when you ran the compiler?

  2. zudov commented on Aug 31, 2015

    @zudov
    ContributorAuthor

    @garyb Yes, sorry. Fixed now.

  3. garyb commented on Aug 31, 2015

    @garyb
    Member

    Just checking :)

    Does it work when MyRecord is not a synonym in the Foo constructor? I don't know whether we can derive generics for records...

  4. zudov commented on Aug 31, 2015

    @zudov
    ContributorAuthor
  5. garyb commented on Aug 31, 2015

    @garyb
    Member

    Cool, it's just "type synonyms again" then. I really need to get around to trying my idea for handling them...

  6. zudov commented on Aug 31, 2015

    @zudov
    ContributorAuthor

    I think the issue arises because Data.Generic defines instances for everything I listed above, but record. When the record is present directly compiler derives it, but if it's behind a type synonym because of some bug compiler doesn't follow the type synonym

  7. modified the milestones: 0.9.0, 0.8.0 on Oct 23, 2015
  8. paf31 commented on Oct 28, 2015

    @paf31
    Contributor

    The error is now

    Error found:
    in module Main
    at 1443.purs line 9, column 1 - line 9, column 39
    
      No type class instance was found for
    
        Data.Generic.Generic { y :: Number
                             , x :: Number
                             }
    
    
    in value declaration fooGeneric
    
  9. self-assigned this
    on Nov 8, 2015
  10. paf31 commented on Nov 14, 2015

    @paf31
    Contributor

    This happens because type synonym desugaring happens after derived instances get elaborated.

  11. 8 remaining items

  12. modified the milestones: 0.10.0, 0.9.0 on Apr 10, 2016
  13. gbaz commented on Apr 26, 2016

    @gbaz

    If there's anything I can do to help here, let me know and I'll take a wack. This is biting us too now that we're using generics in anger.

  14. paf31 commented on Apr 27, 2016

    @paf31
    Contributor

    @gbaz That would be great, but it's not obvious to me how this will be fixed yet. Type synonyms are desugared in the typechecker after instance deriving is done. Perhaps there is a nice way to reuse the Environment if we move the instance deriving into the typechecker, like what I did in my recent PR for the Partial constraint changes.

  15. gbaz commented on Apr 27, 2016

    @gbaz

    I'm passing this along, and I think some people on our team want to start looking at it real soon. We'll keep you up to date if we make progress :-)

  16. modified the milestones: 0.10.0, on Sep 17, 2016
  17. jqyu commented on Sep 28, 2016

    @jqyu

    Is there a reason why type synonyms must be desugared after instance deriving is done? This bug is becoming a blocker for my team as well, and changing the desugaring order sounds like an easy fix.

  18. garyb commented on Sep 28, 2016

    @garyb
    Member

    Unfortunately it's not entirely straightforward as the desugaring happens in two different ways.

    There's an initial desugaring pass that handles a lot of stuff, like making all names fully qualified, desugaring do notation, object wildcards, etc. and the derived instances are also dealt with at this point.

    The type synonyms are desugared during the typechecking pass, which happens after all the other desugaring has been done (and in fact requires it to have been done, it will error if some of the sugar AST cases are encountered).

    I think @paf31 intends to move instance desugaring into the typechecking pass to resolve this, but I've not looked into it myself to see how involved that is. I'm pretty sure you can't just move the desugar function from one place to another though. 😄

  19. jqyu commented on Sep 28, 2016

    @jqyu

    Ah, no wonder I couldn't find the type synonym code, it's in the typechecking pass not the desguaring pass. Thanks for clarifying!

  20. modified the milestones: 1.0, Approved on Oct 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions