Skip to content

ASN.1 PER codegen emits code that fails dialyzer unmatched_returns check #9841

Closed
@ieQu1

Description

@ieQu1

Describe the bug

ASN.1 PER codegen emits the following function in the generated module:

'dialyzer-suppressions'(Arg) ->
    complete(element(1, Arg)),      %% <- warning location
    ok.

It fails dialyzer check when unmatched_returns warning is enabled:

Line XXX Column XXX: Expression produces a value of type bitstring(), but this value is unmatched

To Reproduce

  1. Below is a trivial ASN.1 schema that reproduces the problem:
DSMetadataCommon DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
  EXPORTS ALL;
  TopicWords ::= SEQUENCE OF OCTET STRING
END
  1. It's compiled with the following command:
erlc -bper +noobj -o gen_src asn.1/DSMetadataCommon.asn
  1. Dialyzer runs via rebar3 with the following options:
{dialyzer, [
    {warnings, [unmatched_returns, error_handling]},
    {plt_location, "."},
    {plt_apps, all_apps},
    {statistics, true},
    ...
]}.

Expected behavior

The codegen should generate something like this instead:

'dialyzer-suppressions'(Arg) ->
    _ = complete(element(1, Arg)),
    ok.

I think it should be sufficient to change this line, but I'm no expert.

Alternatively, codegen could emit a pragma disabling this type of warnings.

Affected versions

The error happened to me on OTP27 and 26, but I suspect it affects all recent versions. This particular code was added in 2018.

Additional context
Add any other context about the problem here. If you wish to attach Erlang code you can either write it directly in the post using code tags, create a gist, or attach it as a zip file to this post.

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions