Skip to content

Order of record fields significant when using overload #67

@johnjcamilleri

Description

@johnjcamilleri

Originally reported by Roman Suzi in gf-dev.

When using an overloaded oper with a record as an argument, the order of that record's fields matters:

abstract Test = {
  cat C;
  fun f1, f2, f3, f4, f5: C;
}
concrete TestCnc of Test = {
  param
    Colour = Black | White ;
    Size = Big | Small ;

  oper
    Rec: Type = {
      c: Colour ;
      s: Size ;
    } ;

    mkRec0: Rec -> Rec = \r -> lin C r ;

    mkRec = overload {
      mkRec: Colour -> Size -> Rec = \c,s -> lin C { c = c; s = s } ;
      mkRec: Rec -> Rec = mkRec0 ;
    } ;

  lincat
    C = Rec ;

  lin
    f1 = mkRec White Small ; -- ok

    f2 = mkRec0 { s = Small ; c = White } ; -- ok
    f3 = mkRec0 { c = White ; s = Small } ; -- ok

    f4 = mkRec { s = Small ; c = White } ; -- ok
    f5 = mkRec { c = White ; s = Small } ; -- fails
}

Error for f5:

 TestCnc.gf:28:
   Happened in linearization of f5
    no overload instance of TestCnc.mkRec
    with value type {s : Size; c : Colour}
    for argument list
      {c : Colour; s : Size}
    among alternatives
      Colour Size
      {s : Size; c : Colour}

The enforced order does not seem to be alphabetical (as previously suspected).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions