Skip to content

Commit 704b04b

Browse files
authored
[void-unit-mismatch] void vs unit (#1075)
* [void-unit-mismatch] void vs unit * [void-unit-mismatch] add:returning null does not work either
1 parent 9d350a3 commit 704b04b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package unitAndVoidMismatch
2+
3+
import org.junit.jupiter.api.Test
4+
import org.slf4j.LoggerFactory
5+
6+
fun customGreetingVoid(name: String, greeting: (String) -> Void) = greeting(name)
7+
8+
fun customGreetingUnit(name: String, greeting: (String) -> Unit) = greeting(name)
9+
10+
class UnitAndVoidTypeMismatchUnitTest {
11+
val log = LoggerFactory.getLogger(this::class.java)
12+
13+
@Test
14+
fun `when calling customGreetingVoid method, then code does not compile`() {
15+
/* the below code doesn't compile
16+
---------------------------------
17+
customGreetingVoid("Tom Hanks"){
18+
log.info("Hi $it, how do you do?")
19+
}
20+
21+
customGreetingVoid("Kai"){
22+
log.info("Hello $it")
23+
null
24+
}
25+
*/
26+
}
27+
28+
@Test
29+
fun `when calling customGreetingUnit method, then works as expected`() {
30+
customGreetingUnit("Tom Cruise") {
31+
log.info("Hi $it, how are you doing?")
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)