Skip to content

error: Shell command failure with unused private constructor in opaque type #5127

@poelstra

Description

@poelstra

Running e.g. gleam build on the following program:

type Wibble {
  Wibble
}

pub opaque type Wobble {
  Wobble(Wibble)
}

produces:

warning: Unused private type
  ┌─ /home/martin/src/bt-gleam/src/bug.gleam:1:1
  │
1 │ type Wibble {
  │ ^^^^^^^^^^^ This private type is never used

Hint: You can safely remove it.

warning: Unused private constructor
  ┌─ /home/martin/src/bt-gleam/src/bug.gleam:2:3
  │
2 │   Wibble
  │   ^^^^^^ This private constructor is never used

Hint: You can safely remove it.

warning: Unused private constructor
  ┌─ /home/martin/src/bt-gleam/src/bug.gleam:6:3
  │
6 │   Wobble(Wibble)
  │   ^^^^^^^^^^^^^^ This private constructor is never used

Hint: You can safely remove it.

/home/martin/src/bt-gleam/build/dev/erlang/bt/_gleam_artefacts/bug.erl:6:30: type wibble() undefined
%    6| -opaque wobble() :: {wobble, wibble()}.
%     |                              ^

error: Shell command failure

There was a problem when running the shell command `escript`.

I ran into this while developing. The program doesn't make sense at this point of course, but suppose it should handle this more gracefully.

For reference, here's the compiled erlang:

-module(bug).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/bug.gleam").
-export_type([wobble/0]).

-opaque wobble() :: {wobble, wibble()}.

Seems like the Wibble type isn't emitted because it's 'unused', but then Wobble's constructor is still emitted (even though it's also unused).

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions