https://kotlinlang.org logo
Title
p

Paul Woitaschek

04/16/2019, 8:27 AM
Why isn't this a valid contract? It says "Only references to parameters are allowed in a contract description". What does that mean?
h

hho

04/16/2019, 8:37 AM
It means, you can't reference a property (
value
in this case) in a contract. Only parameters of the method (but yours doesn't have any). Like this maybe? (untested)
@ExperimentalContracts
fun isValidEmail(value: String?): Boolean {
	contract {
		returns(true) implies (value != null)
	}
	return value != null && mailRegex.matches(value)
}
p

Paul Woitaschek

04/16/2019, 8:37 AM
Ah damn, this whould have been to good
h

hho

04/16/2019, 8:52 AM
Hm. I just tried it with one indirection, but the compiler doesn't check it two levels deep 🙍‍♂️ :
s

Stephan Schroeder

04/16/2019, 8:58 AM
hmm, but this is an inline class .. . doesn't that mean
value
is
this
?!?