From 2911f03627c06172ca1e7b4e29915f4fc86351cd Mon Sep 17 00:00:00 2001 From: zakuro Date: Tue, 16 Feb 2021 00:55:54 +0900 Subject: [PATCH] checker: reject method that have multi-value type receiver (#8696) --- vlib/v/checker/checker.v | 2 ++ vlib/v/checker/tests/multi_value_method_err.out | 3 +++ vlib/v/checker/tests/multi_value_method_err.vv | 1 + 3 files changed, 6 insertions(+) create mode 100644 vlib/v/checker/tests/multi_value_method_err.out create mode 100644 vlib/v/checker/tests/multi_value_method_err.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index a83119c3db..a384ca369a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5753,6 +5753,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { c.error('method overrides built-in array method', node.pos) } else if sym.kind == .sum_type && node.name == 'type_name' { c.error('method overrides built-in sum type method', node.pos) + } else if sym.kind == .multi_return { + c.error('cannot define method on multi-value', node.method_type_pos) } if sym.name.len == 1 { // One letter types are reserved for generics. diff --git a/vlib/v/checker/tests/multi_value_method_err.out b/vlib/v/checker/tests/multi_value_method_err.out new file mode 100644 index 0000000000..f5be76a119 --- /dev/null +++ b/vlib/v/checker/tests/multi_value_method_err.out @@ -0,0 +1,3 @@ +vlib/v/checker/tests/multi_value_method_err.vv:1:7: error: cannot define method on multi-value + 1 | fn (v (int, int)) f() {} + | ~~~~~~~~~~ diff --git a/vlib/v/checker/tests/multi_value_method_err.vv b/vlib/v/checker/tests/multi_value_method_err.vv new file mode 100644 index 0000000000..a84f0b654d --- /dev/null +++ b/vlib/v/checker/tests/multi_value_method_err.vv @@ -0,0 +1 @@ +fn (v (int, int)) f() {}