8000 Trait implementations are not checked against the trait's signatures · Issue #642 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Trait implementations are not checked against the trait's signatures #642

Closed

Description

@akoskovacs

A make T, implement: Trait block is checked only for the names of the required functions and their foul markers. The types are not compared with the trait's signatures.

Repro

trait Shape do
  area :> Float
end

record Square do
  side : Float
end

make Square, implement: Shape do
  let area = "not a number"
end

let total(s: Shape) -> Float = s.area + 1.0

main do
  IO.printLine("${total(Square { side: 2.0 })}")
end

Actual: accepted; fails at run time with Cannot add String and Float.

Expected: an error on the make block saying area must return Float.

Cause

TypeChecker::checkTraitImplementation (src/semantic/typechecker.cxx:4509-4573) collects name -> isFoul for the block and compares only those. It should also compare arity, parameter types and result type against the trait's signature with This replaced by the make target.

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 versionTraitsTypechecker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0