Fix syntax bugs
This commit is contained in:
@@ -40,17 +40,17 @@ class Dog : Animal {
|
||||
super(name);
|
||||
}
|
||||
|
||||
override void speak(&self)
|
||||
void speak(&self) override
|
||||
{
|
||||
println!("Woof!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `override` keyword supports explicit base class targeting:
|
||||
The `override` keyword supports explicit base class targeting (Required if overriding a nested parent):
|
||||
|
||||
```mist
|
||||
override(Animal) void speak(&self)
|
||||
void speak(&self) override(Animal)
|
||||
{
|
||||
println!("Woof!");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Functions
|
||||
description: Function declarations, self parameters, return types, and unsafe functions.
|
||||
icon: Function
|
||||
icon: SquareFunction
|
||||
---
|
||||
|
||||
```mist
|
||||
@@ -48,7 +48,7 @@ Functions use **Allman brace style** (opening brace on the next line).
|
||||
|
||||
### Self Parameter
|
||||
|
||||
Methods can take `self`, `&self`, `&mut self`, or `self` with lifetimes:
|
||||
Methods can take `self`, `mut self`, `&self`, `&mut self` additionally with lifetimes:
|
||||
|
||||
```mist
|
||||
pub void set_value(&mut self, i32 v)
|
||||
|
||||
@@ -86,13 +86,13 @@ Macro calls use `!` followed by parentheses, brackets, or braces.
|
||||
let add = (a, b) => a + b;
|
||||
let result = add(2, 3); // 5
|
||||
|
||||
let square = f64 x => x * x;
|
||||
f64 fn() square = (x) => x * x;
|
||||
```
|
||||
|
||||
Closures can have explicit return types:
|
||||
|
||||
```mist
|
||||
let transform = i32 x => {
|
||||
let transform = i32 (x) => {
|
||||
x * 2
|
||||
};
|
||||
```
|
||||
|
||||
@@ -41,5 +41,5 @@ pub void external() { }
|
||||
// Public to specific path
|
||||
pub(crate) void crate_only() { }
|
||||
pub(super) void parent_only() { }
|
||||
pub(in my::module) void module_only() { }
|
||||
pub(my::module) void module_only() { }
|
||||
```
|
||||
|
||||
@@ -9,15 +9,15 @@ icon: Type
|
||||
```mist
|
||||
i32 // Path type
|
||||
str& // Reference type
|
||||
&mut i32 // Mutable reference
|
||||
&'a i32 // Reference with lifetime
|
||||
*const i32 // Const pointer
|
||||
*mut i32 // Mutable pointer
|
||||
i32 mut& // Mutable reference
|
||||
i32 'a& // Reference with lifetime
|
||||
i32 unsafe& // Const pointer
|
||||
i32 mut unsafe& // Mutable pointer
|
||||
(i32, bool) // Tuple type
|
||||
fn(i32) -> bool // Function pointer type
|
||||
Fn(i32) -> bool // Closure trait (Fn)
|
||||
FnMut(i32) -> bool // Closure trait (FnMut)
|
||||
FnOnce(i32) -> bool // Closure trait (FnOnce)
|
||||
bool fn(i32) // Function pointer type
|
||||
bool Fn(i32) // Closure trait (Fn)
|
||||
bool FnMut(i32) // Closure trait (FnMut)
|
||||
bool FnOnce(i32) // Closure trait (FnOnce)
|
||||
dyn Trait // Trait object
|
||||
void // Unit type (maps to Rust's ())
|
||||
'lifetime // Lifetime
|
||||
@@ -32,10 +32,10 @@ type_expr = { (void | path_type | tuple_type | dyn_type) ~ (unsafe_ref_type | re
|
||||
This means types are written left-to-right naturally:
|
||||
|
||||
```mist
|
||||
i32& // &i32
|
||||
i32&mut // &mut i32
|
||||
i32&'a // &'a i32
|
||||
i32 fn() -> bool // fn(i32) -> bool
|
||||
i32& // &i32
|
||||
i32 mut& // &mut i32
|
||||
i32 'a& // &'a i32
|
||||
bool fn(i32) // fn(i32) -> bool
|
||||
```
|
||||
|
||||
### Type Aliases
|
||||
|
||||
Reference in New Issue
Block a user