Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Using type_of(<undeclared>) in a where-clause causes the error message to quadrouple

Open Sanian-Creations opened this issue 2 years ago • 0 comments

Context

Odin: dev-2023-03-nightly:2d71ab6f OS: Windows 10 Home Basic (version: 22H2), build 19045.2604 CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz RAM: 16262 MiB

Expected Behavior

When using a where-clause on a proc to see if a parameter has a specific field of a specific type,

call :: proc(arg: $T) where type_of(arg.field_name) == f32 { }

...it should always print a single error message upon failing (or single set of related error messages), either from the condition returning false or from the type-checker noticing that the field does not exist.

Current bahaviour

When the field does not exist, and this procedure is used within the program, then the exact same error message is printed 4 times.

Failure Information (for bugs)

Likely related to #2362, though this particular bug seems to be more specifically about type_of

  1. The core of the problem has nothing to do with struct members per se, but with trying to call type_of on an undeclared name. A non-existing struct member is one way to achieve that, but it can also be done by simply passing an undeclared identifier like asdf

  2. If the proc is not called anywhere but only defined, then a single error is printed like normal. But calling it anywhere, with whatever argument, will cause an additional 3 errors to be printed, totaling 4. Calling it more than once does not make more errors appear.

Steps to Reproduce

Compile this snippet with odin build report.odin -file -terse-errors (terse errors not needed, but seeing them more compact makes it more clear that they are being duplicated)

package report

call :: proc() where type_of(asdf) == f32 {
	// ...
}

main :: proc() {
	call() // comment out this call and the error is only printed once
}

Failure Logs

Output of compiling the exact snippet above

odin build report.odin -file -terse-errors
C:/code/report.odin(3:30) Error: Undeclared name: asdf
C:/code/report.odin(3:39) Error: 'f32' is not an expression but a type
C:/code/report.odin(3:22) Error: 'where' clauses expect a constant boolean evaluation
C:/code/report.odin(3:30) Error: Undeclared name: asdf
C:/code/report.odin(3:39) Error: 'f32' is not an expression but a type
C:/code/report.odin(3:22) Error: 'where' clauses expect a constant boolean evaluation
C:/code/report.odin(3:30) Error: Undeclared name: asdf
C:/code/report.odin(3:39) Error: 'f32' is not an expression but a type
C:/code/report.odin(3:22) Error: 'where' clauses expect a constant boolean evaluation
C:/code/report.odin(3:30) Error: Undeclared name: asdf
C:/code/report.odin(3:39) Error: 'f32' is not an expression but a type
C:/code/report.odin(3:22) Error: 'where' clauses expect a constant boolean evaluation

Output when the call on line 8 is commented out:

odin build report.odin -file -terse-errors
C:/code/report.odin(3:30) Error: Undeclared name: asdf
C:/code/report.odin(3:39) Error: 'f32' is not an expression but a type
C:/code/report.odin(3:22) Error: 'where' clauses expect a constant boolean evaluation

Sanian-Creations avatar Mar 08 '23 22:03 Sanian-Creations