Skip to content

M0110: Violation of the Strict/Managed boundary ​

error

What it means ​

A tracked (Strict) value crosses into Managed code in a way the checker cannot follow: it goes into a Kotlin collection, into a field of a Managed class, into a Managed or library function parameter that the function keeps (the compiler infers this from the function's body: it stores, returns or hands on the value; functions that only read it, such as println, are fine), or Managed code calls a Strict function that takes or returns ownership.

Minimal failing example ​

From the test corpus: compiler/testdata/memory/boundary_collection.kt. The corpus expects 14:14: M0110 (the ^ comment in the source marks the column).

kotlin
// REJECT M0110: a Strict object goes into a Managed collection (collections of owned values are P3). Spec 5.4, 7.10
@file:MemoryMode(Mode.Strict)

package memory.boundary_collection

import mini.memory.*

class Box(val v: Int)

context(h: Heap)
fun run() {
    val list = ArrayList<Box>()
    val b = Box(1)
    list.add(b)
//           ^ M0110
    b.free()
}

fun main() {
    context(Heap()) { run() }
}

Compiler output ​

Generated by running ./minic check compiler/testdata/memory/boundary_collection.kt (exit status 1).

text
$ ./minic check compiler/testdata/memory/boundary_collection.kt
error[M0110]: Strict value handed to Managed code that keeps it
  --> compiler/testdata/memory/boundary_collection.kt:14:14   parameter `element` of `add` escapes into `refArraySetOwned`, which takes ownership of it (`@TakesOwnership`)
   14 |     list.add(b)
      |              ^
  help: keep the value in Strict code and pass only what is needed (`x.field`), or mark the parameter `@Borrowed` if `add` really only lends it

note: M0110 (Violation of the Strict/Managed boundary): https://henryschwerdt.github.io/mini/reference/diagnostics/M0110

error: could not compile boundary_collection.kt (1 error, 0 warnings)

How to fix ​

Build your own container class from owning fields, wrap the Managed call in a Strict function that frees internally, or mark the Managed parameter @Borrowed if it really only borrows. The message names why the function is considered to keep the value.

Corpus programs for this code ​

See also: Diagnostics overview and the memory guide.

Released under the Apache License 2.0.