diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index 520b9511bf89f7..71d99c2c7e5503 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -255,7 +255,8 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { typ := c.unwrap_generic(node.typ) sym := c.table.final_sym(typ) if sym.kind == .placeholder || typ.has_flag(.generic) { - c.error('unknown type `${sym.name}`', node.typ_pos) + c.error('\$for expects a type name to be used here, but ${sym.name} is not a type name', + node.typ_pos) } if node.kind == .fields { if sym.kind in [.struct_, .interface_] { @@ -268,7 +269,7 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { fields = sym.info.fields.clone() } else { - c.error('comptime field lookup supports only structs and interfaces currently, and ${sym.name} is neither', + c.error('iterating over .fields is supported only for structs and interfaces, and ${sym.name} is neither', node.typ_pos) return } diff --git a/vlib/v/checker/tests/comptime_for.out b/vlib/v/checker/tests/comptime_for.out index 78a99ae18408bd..577fe4f84006a4 100644 --- a/vlib/v/checker/tests/comptime_for.out +++ b/vlib/v/checker/tests/comptime_for.out @@ -11,20 +11,20 @@ vlib/v/checker/tests/comptime_for.vv:3:7: warning: unused variable: `f` | ^ 4 | $for f in T.fields { 5 | $if f.typ is Huh {} -vlib/v/checker/tests/comptime_for.vv:2:12: error: unknown type `Huh` +vlib/v/checker/tests/comptime_for.vv:2:12: error: $for expects a type name to be used here, but Huh is not a type name 1 | fn unknown() { 2 | $for m in Huh.methods {} | ~~~ 3 | $for f in Huh.fields {} 4 | $for f in T.fields { -vlib/v/checker/tests/comptime_for.vv:3:12: error: unknown type `Huh` +vlib/v/checker/tests/comptime_for.vv:3:12: error: $for expects a type name to be used here, but Huh is not a type name 1 | fn unknown() { 2 | $for m in Huh.methods {} 3 | $for f in Huh.fields {} | ~~~ 4 | $for f in T.fields { 5 | $if f.typ is Huh {} -vlib/v/checker/tests/comptime_for.vv:4:12: error: unknown type `T` +vlib/v/checker/tests/comptime_for.vv:4:12: error: $for expects a type name to be used here, but T is not a type name 2 | $for m in Huh.methods {} 3 | $for f in Huh.fields {} 4 | $for f in T.fields {