Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 400
    • Issues 400
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 13
    • Merge requests 13
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Issues
  • #2434
Closed
Open
Created Sep 01, 2024 by Quinten Cabo@QuintenDeveloper

Type inference error in fold

When I compile the following code

module XorAddition;
import Array: {+}; // import + so we can extend it for booleans
use Array: {!=, sel};

export {+};

inline bool +(bool a, bool b) {
    return a != b;
}

bool[d:shp] +(bool[d:shp] a, bool[d:shp] b) {
     return {iv -> a[iv] + b[iv] };
}

and

// Play.sac
use StdIO: {print};
use Array: all except {+};
import Array: {+};
import XorAddition: {+};


int main() {
    r  = with {
            ([0] <= [iv] < [10]) : true;
          }: fold(+, false);

    print(r);

    r  = with {
            ([0] <= [iv] < [128]) : genarray([12,2], 1);
          }: fold(+, genarray([12,2], 0));
    print(r);

    return 0;
}

with:

sac2c -check c XorAddition.sac and then sac2c -check c Play.sac

It gives me:

  No definition found for a function "_MAIN::+" that accepts an argument of type "bool{0}" as parameter no 1. Full argument types are "( bool{0}, bool)".
Compilation failed while Running type inference system.
make: *** [Makefile:51: Play] Fout 53

However compiling:

use StdIO: {print};
use Array: all except {+};
import Array: {+};
import XorAddition: {+};


int main() {
   
    print(true+ true);
    print(1 + 1);

    print([true]+ [true]);
    print([1] + [1]);

    print([[true]]+ [[true]]);
    print([[1]] + [[1]]);

    return 0;
}

with sac2c -check c Play.sac is fine.

When omitting -check c this error does NOT occur.

This makes me believe that something goes wrong when inferring which + should be used in the fold and it can not find the boolean + for some reason.

If you include the code in the XorAddition module at the top of the Play.sac file and do not include the XorAddition module there are also no errors even with -check c.

Edited Sep 01, 2024 by Quinten Cabo
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking