Skip to content

Two errors name the wrong value: a bad + marker reports another parameter, and a double use in a pattern reports another binder #980

Description

@nohzafk

Two checker errors name a value that is not the cause. The rules behind them are clear, and the guide documents both. Only the messages are wrong.

1. The + marker on a Type parameter

A + marker makes a value reusable. The guide says that this marker needs a Data value, and that functions, arrays and IO handles are Type. So the checker refuses + on those values. That refusal is correct.

The message does not say this. It reports expected : Data / observed : Type. It never mentions the marker, the copy, or the parameter. When the def has more than one parameter, the Context block names a different parameter. That parameter is correct.

import Base

def two(+name: String, +res: Result<&1, &1, U32 & String, Unit>) -> Unit:
  Unit{}

Output:

Error:
- expected : Data
- observed : Type
Context:
- name : String
Location: two
3>| def two(+name: String, +res: Result<&1, &1, U32 & String, Unit>) -> Unit:

The offender is res. The Context block names name.

With one parameter, the same error gives no Context block at all:

import Base

def hold(+h: File) -> Unit:
  Unit{}
Error:
- expected : Data
- observed : Type
Location: hold

2. A double use inside a 1n+f pattern

This def matches n, then uses n again in the body. That is two uses of n, and n is affine. The checker refuses it.

The message names f instead. f occurs one time, in the recursive call.

import Base

def count(n: Nat, acc: Nat) -> Nat:
  match n
    case 0n:
      acc
    case 1n+f:
      count(f, (n + acc : Nat))

Output:

Error:
- expected : f
- observed : f (consumed more than once)
Location: count
7>|     case 1n+f:
8 |       count(f, (n + acc : Nat))

The line numbers are correct. The name is not.

What would help

  1. Name the value that breaks the rule. For the + case, that is the marked parameter. For the pattern case, that is the value used two times.
  2. State the rule in the message. For the + case, a sentence such as "+ needs a Data value; this type is Type" would remove the guesswork.

Version

bend 2.0.25   (installed with `bend update`)
bun 1.3.14, Darwin arm64

Related: #957, #964, #965 -- the three bugs this project works around.


The reproducers were run by me with an AI assistant.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions