leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications
https://caramel.run
Apache License 2.0
1.05k stars 25 forks source link

Local function is shadowing imported function with the same name in generated erlang #58

Closed michallepicki closed 3 years ago

michallepicki commented 3 years ago

To Reproduce

  1. Create a file main.ml containing
    
    let print thing = Io.format "~0tp~n" [ thing ]

let weird_join_but_ok list joiner = let join el acc = acc @ [el; 0] in Lists.foldl join [] (Lists.join joiner list)

let main _ = print (weird_join_but_ok [1; 3] 2) ; ()

2. Run command `caramel compile main.ml && escript main.erl`
3. Erlang gets generated with
```erlang
-spec weird_join_but_ok(list(integer()), integer()) -> list(integer()).
weird_join_but_ok(List, Joiner) ->
  Join = fun
  (El, Acc) -> erlang:'++'(Acc, [El | [0 | []]])
end,
  lists:foldl(Join, [], Join(Joiner, List)).
  1. When running, it results in:
    [1,0,3,0,2,0,0,0]

Expected behavior Erlang gets generated with

  lists:foldl(Join, [], lists:join(Joiner, List)).

and running it results in

[1,0,2,0,3,0]

Environment (please complete the following information):

michallepicki commented 3 years ago

Related test (I think): https://github.com/AbstractMachinesLab/caramel/blob/c2562fa4486ec907761ef3a31e839e16ffa29bc7/tests/compiler/expressions.t/names.ml#L18