Universal: fixed syntax issue that should have resulted in compile error

This commit is contained in:
sofusmortensen 2016-09-18 18:09:00 +02:00
parent 9c5ef6cdfe
commit 2299b3beae
3 changed files with 70 additions and 14 deletions

View File

@ -90,6 +90,14 @@ open class ContractBuilder {
fun <T> String.givenThat(@Suppress("UNUSED_PARAMETER") ignore1: T, @Suppress("UNUSED_PARAMETER") ignore2: T) { fun <T> String.givenThat(@Suppress("UNUSED_PARAMETER") ignore1: T, @Suppress("UNUSED_PARAMETER") ignore2: T) {
} }
@Deprecated(level = DeprecationLevel.ERROR, message = "Not available")
fun Party.may(init: ActionBuilder.() -> Action) {
}
@Deprecated(level = DeprecationLevel.ERROR, message = "Not available")
fun Set<Party>.may(init: ActionBuilder.() -> Action) {
}
/* fun Party.gives(beneficiary: Party, amount: Perceivable<Long>, currency: Currency) { /* fun Party.gives(beneficiary: Party, amount: Perceivable<Long>, currency: Currency) {
contracts.add( Transfer(amount, currency, this, beneficiary)) contracts.add( Transfer(amount, currency, this, beneficiary))
}*/ }*/

View File

@ -64,10 +64,12 @@ class ContractDefinition {
actions { actions {
acmeCorp.may { acmeCorp.may {
"exercise".anytime { "exercise".anytime {
(acmeCorp or highStreetBank).may { actions {
"execute".givenThat(after("2017-09-01")) { (acmeCorp or highStreetBank).may {
highStreetBank.gives(acmeCorp, 1.M, EUR) "execute".givenThat(after("2017-09-01")) {
acmeCorp.gives(highStreetBank, 1200.K, USD) highStreetBank.gives(acmeCorp, 1.M, EUR)
acmeCorp.gives(highStreetBank, 1200.K, USD)
}
} }
} }
} }
@ -81,8 +83,52 @@ class ContractDefinition {
} }
@Test /* @Test
fun test() { fun `builder problem - should not compile`() {
val arr = arrange {
actions {
acmeCorp.may {
"execute".anytime {
acmeCorp.may {
"problem".anytime {
highStreetBank.gives(acmeCorp, 1.M, USD)
}
}
}
}
}
}
assert( arr is Actions )
if (arr is Actions) {
assert( arr.actions.size == 1)
}
} }
*/
@Test
fun `builder problem - legal`() {
val arr = arrange {
actions {
acmeCorp.may {
"execute".anytime {
actions {
acmeCorp.may {
"problem".anytime {
highStreetBank.gives(acmeCorp, 1.M, USD)
}
}
}
}
}
}
}
assert( arr is Actions )
if (arr is Actions) {
assert( arr.actions.size == 1)
}
}
} }

View File

@ -22,15 +22,17 @@ class Swaption {
"proceed".givenThat(after("01/07/2015")) { "proceed".givenThat(after("01/07/2015")) {
highStreetBank.gives(acmeCorp, libor(notional, "01/04/2015", "01/07/2015"), currency) highStreetBank.gives(acmeCorp, libor(notional, "01/04/2015", "01/07/2015"), currency)
acmeCorp.gives(highStreetBank, interest(notional, "act/365", coupon, "01/04/2015", "01/07/2015"), currency) acmeCorp.gives(highStreetBank, interest(notional, "act/365", coupon, "01/04/2015", "01/07/2015"), currency)
(highStreetBank or acmeCorp).may { actions {
"proceed".givenThat(after("01/10/2015")) { (highStreetBank or acmeCorp).may {
highStreetBank.gives(acmeCorp, libor(notional, "01/07/2015", "01/10/2015"), currency) "proceed".givenThat(after("01/10/2015")) {
acmeCorp.gives(highStreetBank, interest(notional, "act/365", coupon, "01/07/2015", "01/10/2015"), currency) highStreetBank.gives(acmeCorp, libor(notional, "01/07/2015", "01/10/2015"), currency)
acmeCorp.gives(highStreetBank, interest(notional, "act/365", coupon, "01/07/2015", "01/10/2015"), currency)
actions { actions {
(highStreetBank or acmeCorp).may { (highStreetBank or acmeCorp).may {
"dummy".anytime { zero } "dummy".anytime { zero }
// etc ... // etc ...
}
} }
} }
} }