8000 Type aliases of applied generics are opaque: `type ReadOnlyFile = FileHandle<CanRead, CannotWrite>` matches nothing · Issue #173 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Type aliases of applied generics are opaque: type ReadOnlyFile = FileHandle<CanRead, CannotWrite> matches nothing #173

Closed

Description

@akoskovacs

A type alias whose right-hand side is an applied generic is not expanded by the typechecker. It is treated as a distinct opaque type, so it fails to match even the identical type it aliases.

type ReadOnlyFile = FileHandle<CanRead, CannotWrite>

foul useExact(h: FileHandle<CanRead, CannotWrite>) -> String = "ok"
foul viaAlias(h: ReadOnlyFile) -> String = useExact(h)
error: `useExact` expects argument 1 to be FileHandle<CanRead, CannotWrite>, but got ReadOnlyFile

useExact : FileHandle<CanRead, CannotWrite> -> String

The same happens against a generic signature — this is the case that motivated it:

type ReadOnlyFile = FileHandle<CanRead, CannotWrite>
foul peek(h: ReadOnlyFile) -> String? = h.readLine
error: `readLine` expects argument 1 to be FileHandle<CanRead, A>, but got ReadOnlyFile

readLine : FileHandle<CanRead, A> -> String?

An alias to a non-generic type is transparent and works:

type FilePath = String
let showPath(p: FilePath) -> String = p.length.to(String)   # fine

So the defect is specific to aliases of applied generic types: the alias records the name but never expands to FileHandle<CanRead, CannotWrite> during assignability checking.

Why it matters

FileHandle<R, W> typestate is implemented (docs/typestate-file-plan.md), and its whole ergonomic story depends on naming the common instantiations. Without alias expansion, every signature has to spell out both phantom parameters, and the readable names the design invites (ReadOnlyFile, WriteOnlyFile, ReadWriteFile) cannot be defined at all.

Activity

  1. added this to the 0.4.0 milestone on Aug 21, 2026
  2. added a commit that references this issue on Aug 23, 2026
    c6159d7
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 versionIn ProgressActively being worked onTypechecker

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0