Quick Answer

Extension not available in current scope

Understanding the Issue

Extension functions must be imported or defined in the current scope. This error occurs when the extension is not properly imported or conflicts with other extensions.

The Problem

This code demonstrates the issue:

Kotlin Error
// Problem: Missing import
fun String.smile() = "$this :)"

// In another file:
"hello".smile() // Unresolved reference

The Solution

Here's the corrected code:

Kotlin Fixed
// Solution 1: Import extension
import com.example.smileExtension.smile

// Solution 2: Check receiver type
fun Int.smile() = "$this :)"
"hello".smile() // Still error - wrong type

Key Takeaways

Ensure extensions are properly imported and match the receiver type.