@@ -8372,17 +8372,27 @@ fn (mut c Checker) static_fn_value_from_enum_val(mut node ast.EnumVal, _ string,
83728372 return node.typ
83738373}
83748374
8375- fn (mut c Checker) enum_val_as_static_fn (mut node ast.EnumVal, typ_sym ast.TypeSymbol, fsym ast.TypeSymbol) ast.Type {
8376- fn_name := '${typ_sym.name} __static__${node.val} '
8377- if func := c.table.find_fn (fn_name) {
8378- return c.static_fn_value_from_enum_val (mut node, fn_name, func)
8375+ // static_method_of_enum_val resolves the static method that an `ast.EnumVal`-shaped
8376+ // expression (`Type.method`, syntactically identical to an enum value `Color.red`)
8377+ // refers to. It also checks the final/unaliased symbol, so static methods reached
8378+ // through a supported type alias (`type Alias = Struct; Alias.new`) are found by
8379+ // their real fkey instead of the alias name.
8380+ fn (c &Checker) static_method_of_enum_val (node ast.EnumVal, typ_sym ast.TypeSymbol, fsym ast.TypeSymbol) ? ast.Fn {
8381+ if func := c.table.find_fn ('${typ_sym.name} __static__${node.val} ' ) {
8382+ return func
83798383 }
83808384 if fsym.name != typ_sym.name {
8381- alias_fn_name := '${fsym.name} __static__${node.val} '
8382- if func := c.table.find_fn (alias_fn_name) {
8383- return c.static_fn_value_from_enum_val (mut node, alias_fn_name, func)
8385+ if func := c.table.find_fn ('${fsym.name} __static__${node.val} ' ) {
8386+ return func
83848387 }
83858388 }
8389+ return none
8390+ }
8391+
8392+ fn (mut c Checker) enum_val_as_static_fn (mut node ast.EnumVal, typ_sym ast.TypeSymbol, fsym ast.TypeSymbol) ast.Type {
8393+ if func := c.static_method_of_enum_val (node, typ_sym, fsym) {
8394+ return c.static_fn_value_from_enum_val (mut node, func.name, func)
8395+ }
83868396 return ast.void_type
83878397}
83888398
0 commit comments