V1010 unknown_attribute
Only these attributes exist in v0: @tool, @llm, @external, @total, @contract_test, @deprecated, @server, @test_only on items, and @trust("reason") as an expression (design §2.5).
An error from the resolve phase. sakura explain V1010 prints this explanation offline.
Only these attributes exist in v0: @tool, @llm, @external, @total, @contract_test,
@deprecated, @server, @test_only on items, and @trust("reason") as an expression
(design §2.5). Any other attribute is unknown, any attribute but @trust in expression position
is rejected, and Tool.of takes only a function declared with @tool (§11.2).
Wrong:
@pure
fn double(n: Int) -> Int { n * 2 }Fixed:
fn double(n: Int) -> Int { n * 2 }Wrong program
compiler/tests/ui/V1010_tool_of_lambda.sakura, which the compiler's ui suite runs through sakura check:
import std/tool.{Tool}
pub fn tools() -> Unit { let _ = Tool.of(fn(a: Int) { a }) }sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):
{
"schema_version": "1.0",
"kind": "diagnostic",
"id": "d:f8420bbb4dc5a025",
"code": "V1010",
"severity": "error",
"phase": "resolve",
"message": "`Tool.of` takes a function declared with `@tool`",
"snapshot": "sha256:$SNAPSHOT",
"symbol_id": "main::V1010_tool_of_lambda::tools",
"spans": [
{
"uri": "file://$DIR/V1010_tool_of_lambda.sakura",
"content_hash": "sha256:4a27727b2eaffc7ff21e9bc915c8c8ed6c8622f08151f2d779ae5e1d4b0915ee",
"start_byte": 119,
"end_byte": 144,
"role": "primary"
}
],
"related_ids": [],
"expected": null,
"actual": null,
"obligation": null,
"counterexample": null,
"explanation_uri": "sakura://explain/V1010",
"fixes": []
}More fixtures for this code: compiler/tests/ui/V1010_tool_of_untagged_function.sakura, compiler/tests/ui/V1010_unknown_attribute.sakura.
Fixed program
compiler/tests/ui/V1010_tool_of_lambda.fixed.sakura, which sakura check accepts with no diagnostics:
import std/tool.{Tool}
@tool("Doubles a number.")
pub fn double(a: Int) -> Int { a * 2 }
pub fn tools() -> Unit { let _ = Tool.of(double) }