-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum functions are not documented by v doc #23264
Comments
@[flag]
enum File { read write execute }
fn main() {
$for f in File.methods {
println('${f}')
}
} Code above prints the details of eight methods. Another way to document them is to create an interface, say pub interface EnumFlag
// explaining each of eight methods...
is_empty(...)
has(...)
all(...)
set(...)
set_all(...)
clear(...)
clear_all(...)
toggle(...)
} |
Seems there is a confusion about "static" and "instance" enum build-in methods. For enums with attr @[flag] enum File { read write execute }
fn main() {
assert File.from(4)!.str() == 'File{.execute}'
assert File.zero().str() == 'File{}'
} But I can write my instance methods @[flag] // this adds 8 methods
enum File { read write execute }
//fn (f File) set() { } // duplicated method correctly detected so this line is commented
fn (f File) zero() string { return 'my zero' } // method 9 not detected as duplicated
fn (f File) from() string { return 'my from' } // method 10 not detected as duplicated
fn main() {
mut methods := []string{}
$for m in File.methods {
methods << m.name
}
methods.sort()
assert methods == ['all', 'clear', 'clear_all', 'from', 'has', 'is_empty', 'set', 'set_all', 'toggle', 'zero']
assert File.read.has(File.read | File.write) == true
assert File.read.zero() == 'my zero'
assert File.read.from() == 'my from'
} https://play.vlang.io/p/5d41326dd4 V 0.4.9 7b9b3dd Please notice I cannot duplicate method The confusion I am talking about comes from inspecting the Parser function if is_method {
mut is_duplicate := type_sym.has_method(name)
// make sure this is a normal method and not an interface method
if type_sym.kind == .interface && is_duplicate {
if mut type_sym.info is ast.Interface {
// if the method is in info then its an interface method
is_duplicate = !type_sym.info.has_method(name)
}
}
if is_duplicate {
if type_sym.kind == .enum
&& name in ['is_empty', 'has', 'all', 'set', 'set_all', 'clear', 'clear_all', 'toggle', 'zero', 'from'] { where a list of ten methods (including Anyway this could be an issue to check but the important part is we need documentated the methods build-in for attribute |
Describe the issue
I'd expect enum functions like
Enum.from()
,enum.has
/enum.all
/enum.any
to be documented by vdoc similar to array/map functions using stubs.Links
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Huly®: V_0.6-21698
The text was updated successfully, but these errors were encountered: