M0111: Invalid ownership annotation
error
What it means
@Owned is placed on a type that has no ownership (primitives, String, Managed classes), @Owned and @Borrowed are combined, or @Borrowed contradicts an owning return.
Minimal failing example
From the test corpus: compiler/testdata/memory/annotation_misuse.kt. The corpus expects 8:14: M0111 (the ^ comment in the source marks the column).
kotlin
// REJECT M0111: @Owned on a type that has no ownership (Int). Spec 4.4, 7.11
@file:MemoryMode(Mode.Strict)
package memory.annotation_misuse
import mini.memory.*
fun twice(x: @Owned Int): Int = x * 2
// ^ M0111
fun main() {
println(twice(4))
}Compiler output
Generated by running ./minic check compiler/testdata/memory/annotation_misuse.kt (exit status 1).
text
$ ./minic check compiler/testdata/memory/annotation_misuse.kt
error[M0111]: `@Owned` on `Int`, which has no ownership
--> compiler/testdata/memory/annotation_misuse.kt:8:14 no ownership here
8 | fun twice(x: @Owned Int): Int = x * 2
| ^
help: remove the annotation
note: M0111 (Invalid ownership annotation): https://henryschwerdt.github.io/mini/reference/diagnostics/M0111
error: could not compile annotation_misuse.kt (1 error, 0 warnings)How to fix
Remove the annotation.
Corpus programs for this code
annotation_misuse.kt(8:14), shown above
See also: Diagnostics overview and the memory guide.