Unit can't be called in this context by implicit receiver

This was a kotlin error that I encountered while I was working with Teamcity.
The error message was

Unit can’t be called in this context by implicit receiver

What does this mean?

I am following this Kotlin example (Kotlin DSL | TeamCity On-Premises Documentation) and trying to write a kotlin script for my CI.

This is my code snippet

steps {
    script {
        name = "Style check"
        id("StyleCheck")
        enabled = false
        scriptContent = """
            #!/bin/bash

            make docker run="make ci lint"
        """.trimIndent()
    }

I get an Error for the id() call which says

Error message

  • What does the error message mean?
  • How can I use id() call as given in the example?

Looks like the scripts block does not provide an id method. I think you want id = "StyleCheck" based on one of the examples in that page.

The error is probably there because an id method is provided by one of the surrounding scopes, but the TeamCity DSL has used the @DslMarker attribute to block users from accidentally affecting outer DSL scopes from nested DSL scopes like you seem to be doing. :wink:

See Type-safe builders | Kotlin if curious about @DslMarker.

2 Likes

Thank you, much. This explains how usage in the scope was blocked.