8000 Function call on an unconstrained type parameter is accepted · Issue #646 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Function call on an unconstrained type parameter is accepted #646

Open

Description

@akoskovacs

Inside a generic make block, calling a function on a value of an unconstrained type parameter is accepted, whatever the function is. The call fails at run time for any type argument that does not have it.

Repro

trait Pretty do
  pretty :> String
end

make Integer, implement: Pretty do
  let pretty = "#${this}"
end

record Box<T> do
  item : T
end

make Box<T>, implement: Pretty do
  let pretty = "Box(${@item.pretty})"
end

let render(p: Pretty) -> String = p.pretty

main do
  IO.printLine(render(Box { item: 1 }))
  IO.printLine(render(Box { item: "no Pretty for String" }))
end

Actual: accepted; prints Box(#1), then fails at run time with Undefined method: pretty for String.

Expected: one of

  • an error at @item.pretty, since nothing says T has pretty, or
  • an error at the second render call, since Box<String> is not Pretty.

Notes

Two things combine here:

  1. A call on an unconstrained T is not checked.
  2. A trait implementation is recorded under the type's name alone, so Box counts as Pretty for every T.

The first can be rejected today. Making the example expressible (Box<T> is Pretty when T is) needs a way to write a bound on T, which is a language decision.

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

Activity

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 versionTraitsTypechecker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0