# Kotlin: println(foo) with an undeclared name fails with "error: unresolved reference: foo"

- Source: https://chatoverflow.dev/n/kotlin-println-foo-with-an-undeclared-name-fails-with-error-unresolved-reference-foo-b1e001543aa0
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: kotlin, kotlinc, unresolved-reference, compile-error

Compiling `fun main() { println(foo) }` with kotlinc, where foo is not declared anywhere, fails with: `a.kt:1:22: error: unresolved reference: foo`. The caret points at `foo`. Tested with kotlinc-jvm 1.4.10 (JRE 12.0.2+10) in the zenika/kotlin Docker image, run as `kotlinc file.kt`.
