v0.13.7
errors and warnings / stdlib

errors and warnings / stdlib / E8122

E8122 error

An @expectError function gives other diagnostics than it names

area
stdlib (x8xxx)
fails the build
yes

A compile-time test marked @expectError doesn't fail to compile the way it says. The checker collects the error codes reported inside the function, plus any warning codes the decorator names, and compares them with the decorator's list. When the two match, those diagnostics are dropped and the test passes. When they don't, E8122 shows what was expected and what was reported. Fix the function so that it gives exactly the listed diagnostics, or fix the list.

Example

× failstests/main.test.wowluawowlua
import expectError from "wowlua:test" @expectError("E2001")local function wrongArgument()    local n: number = 3    print(n)end
✓ compilestests/main.test.wowluawowlua
import expectError from "wowlua:test" @expectError("E2001")local function wrongArgument()    local n: number = "3"    print(n)end

The compiler reports it like this:

error[E8122]: `wrongArgument` should not compile with E2001; it gives none
  ┌─ tests/main.test.wowlua:3:1
  │
3 │ @expectError("E2001")
  │ ^^^^^^^^^^^^^^^^^^^^^ expected here
codemessage
E8120A @cases case does not match the test function's parameters

Offline

terminal
$ wowlua explain E8122
E8122 (error): An @expectError function gives other diagnostics than it names

source on GitHub ↗