Skip to content

Say length(xs) to somebody who wrote xs.length() - #211

Merged
onatozmenn merged 1 commit into
mainfrom
typeck/no-methods
Jul 27, 2026
Merged

onatozmenn merged 1 commit into
mainfrom
typeck/no-methods

Conversation

@onatozmenn

Copy link
Copy Markdown
Collaborator

Third one from the newcomer sweep. xs.length() was answered as a missing field:

error[DEED4004]: `List<Int>` has no field `length`
 3 | fn f(xs: List<Int>) -> Int { xs.length() }
   |                                 ^^^^^^ no such field

length is right there, it's a function rather than a method, and the message sends the reader looking for a field that was never going to exist. Now:

 = note: there are no methods: `length` is a function and takes the value as its first
         argument, so this is written `length(x)` rather than `x.length()`

I checked that length really does work on a list before suggesting it, examples/proven.deed:25 has type NonEmptyList = List<Int> where length(value) > 0, so this isn't pointing at a dead end.

The note only appears when the name is a function in scope. A misspelled field still gets the existing "it has alpha" note and nothing about methods, since telling somebody with a typo to call it would be worse than saying nothing. There's a test for that direction too.

No fix offered. Rewriting xs.length() into length(xs) means moving the receiver across the dot and into the argument list, and the diagnostic has the field's span, not the call's, so any edit built here would be a guess about text it can't see.

Investigated with AI assistance.

A field access that names a function used to be answered as a missing
field:

    error[DEED4004]: `List<Int>` has no field `length`
     3 | fn f(xs: List<Int>) -> Int { xs.length() }
       |                                 ^^^^^^ no such field

`length` is right there. It is a function rather than a method, and the
message sends the reader off to look for a field that was never going to
exist, in a language where the thing they wanted is one rearrangement
away.

    = note: there are no methods: `length` is a function and takes the
            value as its first argument, so this is written `length(x)`
            rather than `x.length()`

The note is only added when the name is a function in scope, so a
misspelled field is still a misspelled field and still gets the list of
what the record has. Telling the author of a typo to call it would be
worse than saying nothing.

No fix is offered. Turning `xs.length()` into `length(xs)` means moving
the receiver across the dot and into the argument list, and the
diagnostic here has the field's span and not the call's, so an edit built
from what is known at this point would be a guess about text it cannot
see.
@onatozmenn
onatozmenn merged commit 1f9a973 into main Jul 27, 2026
1 check passed
@onatozmenn
onatozmenn deleted the typeck/no-methods branch July 27, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant