Re: EEP37: Funs with names

Björn Gustavsson <[email protected]>
Newsgroups gmane.comp.lang.erlang.patches
Message-ID <CA+yh78R2j3gzjUawSsnhHN1OrCW8JbNR1H8bL+_DinaZVuGibA@mail.gmail.com>
On Wed, Nov 14, 2012 at 5:42 PM, Anthony Ramine <[email protected]> wrote:

> This patch implements EEP37: Funs with names
>
>
It is now much closer to being graduated.

I have added the branch to our daily builds for the master branch.

I would like a comment from Kostis about the Dialyzer changes.

What also remains is coverage in test suites. I have fixed a few,
but xref_SUITE remains to be fixed (a named fun with the '_' name
should be tested).

Here are my fixes for the test suites (also included as an attachment
to make it easier to apply):

diff --git a/lib/compiler/test/fun_SUITE.erl
b/lib/compiler/test/fun_SUITE.erl
index 0ff846e..e35692e 100644
--- a/lib/compiler/test/fun_SUITE.erl
+++ b/lib/compiler/test/fun_SUITE.erl
@@ -197,10 +197,14 @@ external(Config) when is_list(Config) ->
 call_me(I) ->
     {ok,I}.

-id(I) ->
-    I.
-
 eep37(Config) when is_list(Config) ->
     F = fun Fact(N) when N > 0 -> N * Fact(N - 1); Fact(0) -> 1 end,
+    Add = fun _(N) -> N + 1 end,
+    UnusedName = fun BlackAdder(N) -> N + 42 end,
     720 = F(6),
+    10 = Add(9),
+    50 = UnusedName(8),
     ok.
+
+id(I) ->
+    I.
diff --git a/lib/debugger/test/fun_SUITE.erl
b/lib/debugger/test/fun_SUITE.erl
index 569af6c..75e3b55 100644
--- a/lib/debugger/test/fun_SUITE.erl
+++ b/lib/debugger/test/fun_SUITE.erl
@@ -288,10 +288,14 @@ external(Config) when is_list(Config) ->
 call_me(I) ->
     {ok,I}.

-id(I) ->
-    I.
-
 eep37(Config) when is_list(Config) ->
     F = fun Fact(N) when N > 0 -> N * Fact(N - 1); Fact(0) -> 1 end,
+    Add = fun _(N) -> N + 1 end,
+    UnusedName = fun BlackAdder(N) -> N + 42 end,
     720 = F(6),
+    10 = Add(9),
+    50 = UnusedName(8),
     ok.
+
+id(I) ->
+    I.
diff --git a/lib/stdlib/test/erl_lint_SUITE.erl
b/lib/stdlib/test/erl_lint_SUITE.erl
index ea90793..ad51bfa 100644
--- a/lib/stdlib/test/erl_lint_SUITE.erl
+++ b/lib/stdlib/test/erl_lint_SUITE.erl
@@ -644,7 +644,9 @@ unused_vars_warn_fun(Config) when is_list(Config) ->
               u() ->
                   fun U(U) -> foo end; % U shadowed. U unused.
               u() ->
-                  fun U(1) -> U; U(U) -> foo end. % U shadowed. U unused.
+                  fun U(1) -> U; U(U) -> foo end; % U shadowed. U unused.
+              u() ->
+                  fun _(N) -> N + 1 end.  % Cover handling of '_' name.
            ">>,
            [warn_unused_vars],
            {error,[{3,erl_lint,{unbound_var,'U'}}],


id/1 is a common help function, so I want it to remain at the end
of the file.

/Bjorn

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB

_______________________________________________
erlang-patches mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-patches
0001-fixup-Test-named-funs.patch (text/x-patch, 2.3 KB)
From ddb71a25b7ef49cb2e79409456584fc7a1385eaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <[email protected]>
Date: Thu, 28 Nov 2013 13:09:59 +0100
Subject: [PATCH] fixup! Test named funs

---
 lib/compiler/test/fun_SUITE.erl    |   10 +++++++---
 lib/debugger/test/fun_SUITE.erl    |   10 +++++++---
 lib/stdlib/test/erl_lint_SUITE.erl |    4 +++-
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/compiler/test/fun_SUITE.erl b/lib/compiler/test/fun_SUITE.erl
index 0ff846e..e35692e 100644
--- a/lib/compiler/test/fun_SUITE.erl
+++ b/lib/compiler/test/fun_SUITE.erl
@@ -197,10 +197,14 @@ external(Config) when is_list(Config) ->
 call_me(I) ->
     {ok,I}.
 
-id(I) ->
-    I.
-
 eep37(Config) when is_list(Config) ->
     F = fun Fact(N) when N > 0 -> N * Fact(N - 1); Fact(0) -> 1 end,
+    Add = fun _(N) -> N + 1 end,
+    UnusedName = fun BlackAdder(N) -> N + 42 end,
     720 = F(6),
+    10 = Add(9),
+    50 = UnusedName(8),
     ok.
+
+id(I) ->
+    I.
diff --git a/lib/debugger/test/fun_SUITE.erl b/lib/debugger/test/fun_SUITE.erl
index 569af6c..75e3b55 100644
--- a/lib/debugger/test/fun_SUITE.erl
+++ b/lib/debugger/test/fun_SUITE.erl
@@ -288,10 +288,14 @@ external(Config) when is_list(Config) ->
 call_me(I) ->
     {ok,I}.
 
-id(I) ->
-    I.
-
 eep37(Config) when is_list(Config) ->
     F = fun Fact(N) when N > 0 -> N * Fact(N - 1); Fact(0) -> 1 end,
+    Add = fun _(N) -> N + 1 end,
+    UnusedName = fun BlackAdder(N) -> N + 42 end,
     720 = F(6),
+    10 = Add(9),
+    50 = UnusedName(8),
     ok.
+
+id(I) ->
+    I.
diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl
index ea90793..ad51bfa 100644
--- a/lib/stdlib/test/erl_lint_SUITE.erl
+++ b/lib/stdlib/test/erl_lint_SUITE.erl
@@ -644,7 +644,9 @@ unused_vars_warn_fun(Config) when is_list(Config) ->
               u() ->
                   fun U(U) -> foo end; % U shadowed. U unused.
               u() ->
-                  fun U(1) -> U; U(U) -> foo end. % U shadowed. U unused.
+                  fun U(1) -> U; U(U) -> foo end; % U shadowed. U unused.
+              u() ->
+                  fun _(N) -> N + 1 end.  % Cover handling of '_' name.
            ">>,
            [warn_unused_vars],
            {error,[{3,erl_lint,{unbound_var,'U'}}],
-- 
1.7.9.5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.