8000 Atom literal types are not enforced: :banana is accepted as :ok | :error · Issue #641 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Atom literal types are not enforced: :banana is accepted as :ok | :error #641

Closed

Description

@akoskovacs

docs/types.md (Atoms) says an atom can be used as a type that accepts only that value, and that a union of atoms restricts a value to that set. The checker does not enforce it.

Repro

let status: :ok | :error = :banana

main do
  IO.printLine("${status}")
end

Actual: accepted; prints :banana.

Expected: Type mismatch: expected :ok | :error, got :banana.

Cause

An atom literal is inferred as a nameless Atom (src/semantic/typechecker_expr.cxx:530), and the name an atom type was written with is kept for display only: every comparison ignores it (src/semantic/types.hxx:23-28).

A fix has to keep the literal name on the inferred type and then drop it where the value stops being that literal (an unannotated let, a type variable being bound, joined branches), or programs that reassign or collect different atoms would start failing.

Reproduced on kex 0.4.0-rc.3 (266b7a60) with the type checker on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingConfirmed IssueBug is reproduced on the current development versionTypechecker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0