Skip to content

Commit 84f85b5

Browse files
authored
shouldNotUseVoidMethodAsValue (#134)
1 parent d574d57 commit 84f85b5

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

test/validations/shouldNotUseVoidMethodAsValue.wlk

+16-29
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ object pepita {
22
var energy = 0
33

44
// self is the void method
5-
method eat(something) {
5+
method ingest(something) {
66
energy -= something
77
}
8+
89
}
910

1011
class A {
@@ -17,34 +18,29 @@ class MethodsCalledOnWellKnowObjects inherits A {
1718

1819

1920
method asParameter() {
20-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
21-
self.setA(pepita.eat(10))
21+
self.setA(@Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10)))
2222
}
2323

2424
method initialization(aParam) {
25-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
26-
const a = pepita.eat(10)
25+
const a = @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10))
2726

2827
self.setA(a)
2928
}
3029

3130
method assignment(aParam) {
3231
var a = null
3332

34-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
35-
a = pepita.eat(10)
33+
a = @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10))
3634

3735
self.setA(a)
3836
}
3937

4038
method asReturnValue() {
41-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
42-
return pepita.eat(10)
39+
return @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10))
4340
}
4441

4542
method asAnIfCondition() {
46-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
47-
return if (pepita.eat(10))
43+
return if (@Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10)))
4844
20
4945
else
5046
30
@@ -53,39 +49,30 @@ class MethodsCalledOnWellKnowObjects inherits A {
5349
method asABinaryOperatorArgument() {
5450
const cond = true
5551
return [
56-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
57-
10 + pepita.eat(10),
58-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
59-
10 * pepita.eat(10),
60-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
61-
cond && pepita.eat(10),
62-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
63-
cond || pepita.eat(10)
52+
10 + @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10)),
53+
10 * @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10)),
54+
cond && @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10)),
55+
cond || @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10))
6456
]
6557
}
6658

6759
method asTargetForNewMessageSend() {
68-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
69-
pepita.eat(10).cantina()
60+
(@Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10))).cantina()
7061
}
7162

7263
method asListLiteralElement() {
73-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
74-
return [1, 2, 3, pepita.eat(10)]
64+
return [1, 2, @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10))]
7565
}
7666

7767
override method toBeOverriden(a) {
78-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
79-
super(pepita.eat(10))
68+
super(@Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10)))
8069
}
8170

8271
method asConstructorArg() {
83-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
84-
return new B(a = pepita.eat(10))
72+
return new B(a = @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10)))
8573
}
8674

87-
// XPECT errors --> "Message send "eat(10)" produces no value (missing return in method?)" at "eat"
88-
method asExpressionOnMethodShortcut() = pepita.eat(10)
75+
method asExpressionOnMethodShortcut() = @Expect(code = "shouldNotUseVoidMethodAsValue", message = "error") (pepita.ingest(10))
8976
}
9077

9178
class B {

0 commit comments

Comments
 (0)