File 2972-Add-test-cases-for-precedence-of-function-applicatio.patch of Package erlang
From 9af30eec9e2033f25f0725c2a69ad453adc0f6d4 Mon Sep 17 00:00:00 2001
From: Richard Carlsson <carlsson.richard@gmail.com>
Date: Fri, 16 May 2025 10:35:31 +0200
Subject: [PATCH 2/2] Add test cases for precedence of function application
---
lib/compiler/test/apply_SUITE.erl | 11 +++++++++--
lib/compiler/test/fun_SUITE.erl | 14 ++++++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/lib/compiler/test/apply_SUITE.erl b/lib/compiler/test/apply_SUITE.erl
index df0dae41af..120ccfec8e 100644
--- a/lib/compiler/test/apply_SUITE.erl
+++ b/lib/compiler/test/apply_SUITE.erl
@@ -23,9 +23,9 @@
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
init_per_group/2,end_per_group/2,
- mfa/1,fun_apply/1,involved/1]).
+ mfa/1,fun_apply/1,precedence/1,involved/1]).
--export([foo/0,bar/1,baz/2]).
+-export([foo/0,bar/1,baz/2,get_callback/0]).
-include_lib("common_test/include/ct.hrl").
@@ -38,6 +38,7 @@ groups() ->
[{p,test_lib:parallel(),
[mfa,
fun_apply,
+ precedence,
involved
]}].
@@ -139,6 +140,12 @@ fun_apply(Config) when is_list(Config) ->
ok.
+get_callback() ->
+ lists.
+
+precedence(_Config) ->
+ [3,2,1] = ?MODULE:get_callback():reverse([1,2,3]).
+
involved(_Config) ->
self() ! message,
ok = involved_1(),
diff --git a/lib/compiler/test/fun_SUITE.erl b/lib/compiler/test/fun_SUITE.erl
index 96dd1546f9..5984484ad8 100644
--- a/lib/compiler/test/fun_SUITE.erl
+++ b/lib/compiler/test/fun_SUITE.erl
@@ -26,7 +26,7 @@
test1/1,overwritten_fun/1,otp_7202/1,bif_fun/1,
external/1,eep37/1,badarity/1,badfun/1,
duplicated_fun/1,unused_fun/1,parallel_scopes/1,
- coverage/1,leaky_environment/1]).
+ coverage/1,leaky_environment/1,chain/1]).
%% Internal exports.
-export([call_me/1,dup1/0,dup2/0]).
@@ -40,7 +40,7 @@ all() ->
groups() ->
[{p,[parallel],
- [test1,overwritten_fun,otp_7202,bif_fun,external,eep37,
+ [test1,overwritten_fun,otp_7202,bif_fun,external,eep37,chain,
badarity,badfun,duplicated_fun,unused_fun,
parallel_scopes,
coverage,leaky_environment]}].
@@ -204,13 +204,16 @@ external(Config) when is_list(Config) ->
42 = (fun erlang:abs/1)(-42),
42 = (id(fun erlang:abs/1))(-42),
+ 42 = id(fun erlang:abs/1)(-42),
42 = apply(fun erlang:abs/1, [-42]),
42 = apply(id(fun erlang:abs/1), [-42]),
6 = (fun lists:sum/1)([1,2,3]),
6 = (id(fun lists:sum/1))([1,2,3]),
+ 6 = id(fun lists:sum/1)([1,2,3]),
{'EXIT',{{badarity,_},_}} = (catch (fun lists:sum/1)(1, 2, 3)),
{'EXIT',{{badarity,_},_}} = (catch (id(fun lists:sum/1))(1, 2, 3)),
+ {'EXIT',{{badarity,_},_}} = (catch id(fun lists:sum/1)(1, 2, 3)),
{'EXIT',{{badarity,_},_}} = (catch apply(fun lists:sum/1, [1,2,3])),
{'EXIT',{badarg,_}} = (catch bad_external_fun()),
@@ -225,6 +228,11 @@ bad_external_fun() ->
fun V0:V0/V0, %Should fail.
never_reached.
+chain(_Config) ->
+ F3 = fun (A, B, C) -> {ok, (A + B) * C} end,
+ F0 = fun (A) -> fun (B) -> fun (C) -> F3(A,B,C) end end end,
+ {ok, 42} = F0(-2)(9)(6).
+
%% Named funs.
eep37(_Config) ->
eep37_basic(),
@@ -243,7 +251,9 @@ eep37_basic() ->
eep37_dup() ->
dup1 = (dup1())(),
+ dup1 = dup1()(),
dup2 = (dup2())(),
+ dup2 = dup2()(),
ok.
dup1() ->
--
2.51.0