louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | // Import ergonomics (issue #297): a local named like an imported module |
| 2 | // shadows it (W0101) and the failing `local.item` access says so, and an |
| 3 | // import nothing uses is drift (W0102). |
| 4 | |
| 5 | import std/dict as d |
| 6 | import std/http/cookie //~ WARN W0102 never used |
| 7 | import std/io |
| 8 | import std/list |
| 9 | import std/option.{is_some} |
| 10 | import std/random //~ WARN W0102 never used |
| 11 | import std/string.{repeat} //~ WARN W0102 never used |
| 12 | import std/time |
| 13 | |
| 14 | // A parameter named like an imported module shadows it; the field access |
| 15 | // that follows fails, with a note pointing at the parameter. |
| 16 | fn total :: |
| 17 | list: List<Int> //~ WARN W0101 shadows the imported module |
| 18 | -> Int |
| 19 | { |
| 20 | list.length list //~ ERROR E0206 several constructors |
| 21 | } |
| 22 | |
| 23 | // Shadowing warns even without a qualified access. |
| 24 | fn head_or_zero :: list: List<Int> -> Int |
| 25 | //~^ WARN W0101 shadows the imported module |
| 26 | { |
| 27 | match list { [] -> 0, [x, ..] -> x } |
| 28 | } |
| 29 | |
| 30 | // A local whose name no import bears shadows nothing; an import renamed |
| 31 | // with `as` binds only its alias (`d`, not `dict`). |
| 32 | fn describe :: server: String dict: d.Dict<Int, Int> -> String |
| 33 | { |
| 34 | server |
| 35 | } |
| 36 | |
| 37 | // A module used only in types and effect rows is used. |
| 38 | fn with_clock :: f: fn() -> Int / <time.clock> -> Int / <time.clock> |
| 39 | { |
| 40 | f () |
| 41 | } |
| 42 | |
| 43 | // An item imported by name and used by name: the import is used. |
| 44 | fn present :: x: Option<Int> -> Bool |
| 45 | { |
| 46 | is_some x |
| 47 | } |
| 48 | |
| 49 | // The prelude needs no import. |
| 50 | fn shown :: -> String |
| 51 | { |
| 52 | show 1 |
| 53 | } |
| 54 | |
| 55 | pub fn main :: -> () / <io> |
| 56 | { |
| 57 | io.println (show (total (list.range 1 3))) |
| 58 | } |