mingkangpan
05/26/2019, 2:54 PM@SqlMarker
object SQLBuilder {
fun query(init: SqlSelectBuilder.() -> Unit): SqlSelectBuilder {
val builder = SqlSelectBuilder()
builder.init()
return builder
}
}
I have this, but somehow the compiler still let me do this eventough I marked it with DSLMarker
val query = SQLBuilder.query {
query {
}
what am I doing wrong? 😞karelpeeters
05/26/2019, 3:24 PMmingkangpan
05/26/2019, 3:26 PMmingkangpan
05/26/2019, 3:26 PMsqlbuilderkarelpeeters
05/26/2019, 3:28 PMmingkangpan
05/26/2019, 3:29 PMkarelpeeters
05/26/2019, 3:30 PMkarelpeeters
05/26/2019, 3:30 PMkarelpeeters
05/26/2019, 3:31 PMkarelpeeters
05/26/2019, 3:31 PMimport com.minki.sqlbuilder.SQLBuilder.querymingkangpan
05/26/2019, 3:32 PMkarelpeeters
05/26/2019, 3:33 PMmingkangpan
05/26/2019, 3:34 PMselect {
select {
}
eventough I have this
@SqlMarker
class SqlSelectBuilderkarelpeeters
05/26/2019, 3:35 PM@SqlMarker on the Select class.mingkangpan
05/26/2019, 3:40 PM@SqlMarker, I still can do this:
or {
or { }
}
why?karelpeeters
05/26/2019, 3:42 PMor brings an explicit new Condition into scope, which you then call the second or on.mingkangpan
05/26/2019, 3:45 PMbrings an explicit new what do you mean exactly by that? because I construct a new object?karelpeeters
05/26/2019, 3:49 PM@DslMarker is to prevent receivers from the upper scopes being accidentally visible in the more nested scopes.
where { //1
or { //2
or { //3
1 calls its lambda with a Condition scope, and on that scope you call or 2. Then 2 calls its lambda with a new Condition receiver, and on that new receiver you can still call or. 2's lambda shouldn't be able to access 1's Condition, and indeed it can't, it uses 2's Condition instead.karelpeeters
05/26/2019, 3:54 PMCondition object in the or code and it'd still work the same. This is a compile-time thing, not a runtime thing.mingkangpan
05/26/2019, 3:54 PMkarelpeeters
05/26/2019, 3:55 PMkarelpeeters
05/26/2019, 3:56 PMmingkangpan
05/26/2019, 3:58 PM