You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/types.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,7 +220,7 @@ fun CanReassign(var str: String): Void {
220
220
## Type System Characteristics
221
221
222
222
**Static typing:** Every variable and expression has a type checked at compile time
223
-
**No implicit conversions except builtin wrappers:**Explicit casting required between different types, except for conversions between primitive reference types and their corresponding fundamentals.
223
+
**Limited implicit conversions:**The compiler only performs implicit conversions between a primitive reference type and its matching fundamental (for example, `Int` ↔ `int`). Any conversion across different primitive families—such as `Int` to `Float` or `Float` to `int`—must use an explicit cast.
224
224
**Type safety:** Prevents many common errors
225
225
**Nullable types:** Any reference type (including primitive reference types) can be made nullable by appending `?`. Fundamental types cannot be nullable.
226
226
@@ -233,11 +233,11 @@ val intVal: int = 42
233
233
val floatVal: float = 3.14
234
234
val result: float = (intVal as float) + floatVal // OK: Explicit conversion
235
235
236
-
// Using primitive reference types (implicit conversion)
237
-
val refInt: Int = 42 // Implicit conversion from literal
238
-
val refFloat: Float = 3.14 // Implicit conversion from literal
239
-
val sum: Int = refInt + (refFloat as Int) // Explicit conversion
240
-
val fundamentalSum: int = sum + 10 // Implicit: Int + int -> int
236
+
// Using primitive reference types (implicit conversion between wrappers and fundamentals)
237
+
val refInt: Int = 42 // Implicit conversion from literal to Int
238
+
val refFloat: Float = 3.14 // Implicit conversion from literal to Float
239
+
val sum: Int = refInt + (refFloat as Int) // Requires explicit narrowing
240
+
val fundamentalSum: int = sum + 10 // Implicit: Int -> int when assigning to a fundamental
241
241
242
242
// Converting nullable primitives to fundamentals
243
243
val nullableInt: Int? = 42 // Implicit conversion from literal
0 commit comments