Skip to content

Commit 84534ec

Browse files
committed
docs: clarify type system characteristics in types.md
Update the documentation to specify that explicit casting is required between different types, with the exception of conversions between primitive reference types and their corresponding fundamentals. Adjust code examples to reflect this change, enhancing clarity and understanding of the type system.
1 parent 8e4b2eb commit 84534ec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/reference/types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fun CanReassign(var str: String): Void {
220220
## Type System Characteristics
221221

222222
**Static typing:** Every variable and expression has a type checked at compile time
223-
**No implicit conversions:** Explicit casting required between different types
223+
**No implicit conversions except builtin wrappers:** Explicit casting required between different types, except for conversions between primitive reference types and their corresponding fundamentals.
224224
**Type safety:** Prevents many common errors
225225
**Nullable types:** Any reference type (including primitive reference types) can be made nullable by appending `?`. Fundamental types cannot be nullable.
226226

@@ -236,7 +236,7 @@ val result: float = (intVal as float) + floatVal // OK: Explicit conversion
236236
// Using primitive reference types (implicit conversion)
237237
val refInt: Int = 42 // Implicit conversion from literal
238238
val refFloat: Float = 3.14 // Implicit conversion from literal
239-
val sum: Int = refInt + refFloat // Implicit: Int + Float -> Int
239+
val sum: Int = refInt + (refFloat as Int) // Explicit conversion
240240
val fundamentalSum: int = sum + 10 // Implicit: Int + int -> int
241241
242242
// Converting nullable primitives to fundamentals

0 commit comments

Comments
 (0)