Skip to content

fix(instance)!: stop generator { } from silently calling the InstanceContainer - #23

Merged
oglassdev merged 1 commit into
refactor/dsl-marker-placementfrom
fix/instance-dsl-scope
Oct 14, 2026
Merged

oglassdev merged 1 commit into
refactor/dsl-marker-placementfrom
fix/instance-dsl-scope

Conversation

@oglassdev

Copy link
Copy Markdown
Owner

Stacked on #22. Merge that first.

@InstanceDsl never protected anything: it was only ever placed on the buildInstance function, where a DSL marker has no effect. So inside generator { }, unqualified calls quietly resolved to the enclosing InstanceContainer:

buildInstance {
    generator {
        setChunkSupplier(...)   // compiled: InstanceContainer's method, called from inside a generator
    }
}

Minestom runs generators during world generation, possibly on worker threads, so touching the instance from there is almost always a mistake.

Now the buildInstance and generator lambda receivers are marked @InstanceDsl, so those calls need an explicit this@buildInstance. modify { } stays unmarked on purpose, so GenerationUnit calls like absoluteStart() still work inside it.

Code Before After
buildInstance { generator { setGenerator(null) } } compiles blocked
generator { modify { setChunkSupplier(null) } } compiles blocked
generator { modify { fill(absoluteStart(), absoluteEnd(), STONE) } } compiles compiles

As a side effect, buildInstance { } and generator { } get IDE DSL coloring again, from the marked lambda (IntelliJ 2026.2+).

Breaking change

Code that relied on the leak needs an explicit receiver (this@buildInstance.…).

Testing

  • Scope probe above compiled against this branch.
  • compileKotlin, compileTestKotlin and :example:compileKotlin pass. The example's generator { modify { fillHeight(...) } } is unaffected.

… generator

The marker was never applied to a lambda type, so code inside
generator { } could implicitly call the enclosing InstanceContainer.
modify { } stays unmarked so GenerationUnit calls remain available.

BREAKING CHANGE: implicit InstanceContainer calls inside generator { }
no longer compile; use this@buildInstance explicitly.
@oglassdev
oglassdev force-pushed the fix/instance-dsl-scope branch from 13949f8 to d7b1f66 Compare October 14, 2026 22:52
@oglassdev
oglassdev added this pull request to stack #24 October 14, 2026 23:16
@oglassdev
oglassdev merged commit 42d360a into main Oct 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant