checker: split fn_decl into functions to cleanup (#9226)

pull/9176/head^2
zakuro 2021-03-11 03:18:48 +09:00 committed by GitHub
parent 791dec7b01
commit ef73e07e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 48 deletions

View File

@ -285,7 +285,13 @@ fn (mut c Checker) check_valid_pascal_case(name string, identifier string, pos t
pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
match node {
ast.AliasTypeDecl {
ast.AliasTypeDecl { c.alias_type_decl(node) }
ast.FnTypeDecl { c.fn_type_decl(node) }
ast.SumTypeDecl { c.sum_type_decl(node) }
}
}
pub fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
// TODO Replace `c.file.mod.name != 'time'` by `it.language != .v` once available
if c.file.mod.name != 'time' && c.file.mod.name != 'builtin' {
c.check_valid_pascal_case(node.name, 'type alias', node.pos)
@ -301,7 +307,8 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
c.error('aliases of `chan` types are not allowed.', node.pos)
}
}
ast.FnTypeDecl {
pub fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl) {
c.check_valid_pascal_case(node.name, 'fn type', node.pos)
typ_sym := c.table.get_type_symbol(node.typ)
fn_typ_info := typ_sym.info as table.FnType
@ -317,7 +324,8 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
}
}
}
ast.SumTypeDecl {
pub fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl) {
c.check_valid_pascal_case(node.name, 'sum type', node.pos)
mut names_used := []string{}
for variant in node.variants {
@ -336,8 +344,6 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
names_used << sym.name
}
}
}
}
pub fn (mut c Checker) interface_decl(decl ast.InterfaceDecl) {
c.check_valid_pascal_case(decl.name, 'interface name', decl.pos)