Has anyone made a `@Bridged` KSP plugin yet that g...
# language-evolution
y
Has anyone made a
@Bridged
KSP plugin yet that generates contextual bridge functions?
j
That would be a nice compiler plugin tho
e
What so you mean by "contextual bridged functions"
y
Bridge functions to make something available through a context. E.g. if I have a Logger interface
Copy code
interface Logger {
  fun log(msg: String)
}
To make this available contextually, I have to write a function:
Copy code
context(l: Logger)
fun log(msg: String) = l.msg()
But I'd like this to just get generated through an annotation instead
e
Okay but annotating what? Logger class makes no sense (to me) ie will you annotate the class then its available everywhere? Actual function will need more information than a simple (parameterless) annotation
y
I'm imagining something like:
Copy code
interface Logger {
  @Bridged
  fun log(msg: String)
}
which generates the context function as above Or even:
Copy code
@Bridged
interface Logger {
  fun log(msg: String)
  fun logd(msg: String)
  ...
}
to have it done to multiple methods
K 2
e
Okay misunderstood initially. Initially I thought you wanted to annotate it and have it available as contextual parameter to other functions outside. But now I'm thinking how is that actually useful? To be able to call it, you will be going from
Copy code
fun myLogic(logger: Logger) {
  logger.log(...)
}

// OR with context parameters

context(logger: logger)
fun myLogic() {
  logger.log(...)
}
to
Copy code
fun myLogic(logger: Logger) {
  logger.run {
    log(...)
  }
}
Pardon the questions but I am genuinely struggling to see the usefulness 🤔
y
You can then do:
Copy code
context(_: logger)
fun myLogic() {
  log(...)
}
Maybe
Logger
isn't the best example. Think
async
for instance.
j
Instead of needing to do this in the body of the function:
Copy code
logger.log(“…”)
You can just
Copy code
log(“…”)
e
Okay I get it now. You want to skip the contextual parameter declaration everywhere
1
c
Yes, for example in DSLs it's useless to give a name to the receiver