Revamp private/public functions

Problem: having public as the default makes it very easy to accidentally
export local function by forgetting the `private` modifier.

Solution: functions are private by default and must be declared as `entrypoint`s
to be exported. So `entrypoint foo() = ...` instead of `function foo() = ...`.

We still accept the `private` modifier although it is redundant.
This commit is contained in:
Ulf Norell
2019-06-27 12:10:25 +02:00
parent dd5fc17554
commit 79137e058e
7 changed files with 110 additions and 24 deletions
+4 -5
View File
@@ -1006,13 +1006,12 @@ add_fun_env(Env = #{ fun_env := FunEnv }, Decls) ->
Env#{ fun_env := maps:merge(FunEnv, FunEnv1) }.
make_fun_name(#{ context := Context }, Ann, Name) ->
Private = proplists:get_value(private, Ann, false) orelse
proplists:get_value(internal, Ann, false),
Entrypoint = proplists:get_value(entrypoint, Ann, false),
case Context of
{main_contract, Main} ->
if Private -> {local_fun, [Main, Name]};
Name == "init" -> init;
true -> {entrypoint, list_to_binary(Name)}
if Name == "init" -> init;
Entrypoint -> {entrypoint, list_to_binary(Name)};
true -> {local_fun, [Main, Name]}
end;
{namespace, Lib} ->
{local_fun, [Lib, Name]}