Skip to content

Support extending annotations for builtin types metamethods #1293

Closed
@nathanpage-credo

Description

@nathanpage-credo

Penlight comes with the ability to inject a format operator into string's __mod metamethod. This greatly shortens creating formatted strings.

The issue is that the following code returns a diagnostic error:

---@type string
local a = "%d %d" % {2, 3}
[{
	"resource": "/home/nate/Documents/csdk/credo/crlua/libs/commands/slice.lua",
	"owner": "_generated_diagnostic_collection_name_#6",
	"code": "param-type-mismatch",
	"severity": 4,
	"message": "Cannot assign `number` to parameter `string`.",
	"source": "Lua Diagnostics.",
	"startLineNumber": 57,
	"startColumn": 38,
	"endLineNumber": 57,
	"endColumn": 68
}]

It considers that the % will return a number instead of a string.

This does make sense in general, but I see no way to override this feature in #499.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions