From c9bb64f18b7dc3b3a375f99c529c069656519192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 7 Oct 2021 10:07:27 +0200 Subject: sys_core_fold: Don't replace bad binary segments with error(badarg) Keep warnings for binary construction that will fail, but don't replace the construction with an `error(badarg)` call to allow the runtime system to add extended information to the exception. For example, `sys_core_fold` will no longer replace the following code: <> with a call to `error(badarg)`. However, note that v3_core still replaces obviously bad types and sizes with a call to `error(badarg)`. For example, `v3_core` will replace the following construction with a call to `error(badarg)`: <> --- lib/compiler/src/sys_core_fold.erl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index 3653d5e647..7a0bf0c34e 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -601,10 +601,7 @@ eval_binary(#c_binary{anno=Anno,segments=Ss}=Bin) -> Bin; throw:{badarg,Warning} -> add_warning(Bin, {failed,Warning}), - #c_call{anno=Anno, - module=#c_literal{val=erlang}, - name=#c_literal{val=error}, - args=[#c_literal{val=badarg}]} + Bin end. eval_binary_1([#c_bitstr{val=#c_literal{val=Val},size=#c_literal{val=Sz}, -- cgit v1.2.1