MoxyMoxy
Docs contents

Starter tasks

Ten small, concrete tasks found by reading the code, each reproduced against 0.3.1 with build/moxy. They don't need compiler internals beyond the one file named. Say in the issue that you're taking one so two people don't do the same work. CONTRIBUTING.md explains how to build and test.

These are listed here because creating issues is a maintainer step. When a task becomes a GitHub issue, label it good first issue and link back to this line.

Tests for diagnostics that have none

docs/errors.md documents these messages, and tests/fail/ has no test for any of them (it covers 11 diagnostics). A test is a .mxy file in tests/fail/ and a .err file next to it with the message. Copy tests/fail/addnumber.mxy and .err as a template.

  1. strings are immutable; build a new string instead: src/sema/expr.mxy:234. Reproduce with string s = "abc"; s[0] = (char)120;.
  2. weak fields must hold a ref struct and struct 'N' cannot contain itself: src/sema/decl.mxy:194 and :196. Two tests: struct P { int v; } struct A { weak P p; } (a weak int x; is a syntax error instead) and struct N { int v; N next; }.
  3. main must return void or int and function 'f' is defined twice: src/sema/decl.mxy:247 and :51. The second also prints a note pointing at the first definition; the test should check the note.
  4. cannot infer the element type of an empty list: src/sema/expr.mxy:362. Reproduce with auto xs = [];. The message is followed by a hint (line 363); check that too.

Standard library bugs

Each has a one-line reproduction. Fix it and add a test under tests/ (see item 9).

  1. pow_int ignores a negative exponent and overflows silently: std/math.mxy:34. pow_int(2, -1) returns 1 and pow_int(2, 70) returns 0. Decide the behavior (panic on a negative exponent is the simplest; say what you choose for overflow), document it in the file's comment, and test it.
  2. run reports success when the command is killed by a signal: std/os.mxy:19. run("kill -9 $$") returns 0, because the exit status is taken as (status >> 8) & 255 without checking WIFEXITED. Return 128 + signal as shells do, or -1, and document which.
  3. reverse corrupts UTF-8: std/string.mxy:24. reverse("héllo") produces invalid bytes because it reverses bytes. Either reverse by code point, or rename and document the byte-wise behavior. It also builds the result with repeated +, which is quadratic.
  4. read_lines can't tell a missing file from an empty one: std/io.mxy:29. It returns [] for both. Add a Result<string[]> variant, or make it return the error, and keep the old one only if the docs say what it hides.

Tooling and tests

  1. Tests for std/io, std/os and std/time: nothing under tests/ or examples/ includes them; examples/stdlib.mxy covers debug, math, string and test only. Add tests/std/ with a test per module: read_file/write_file/append_file round trip in a temp file, env and has_env, run exit codes, and monotonic_ms never going backwards. Items 5 to 8 can add their tests here too.
  2. Language server completion is missing keywords and the standard library: tools/moxylsp/lsp.mxy:126. The keyword list has match and in but not defer, namespace, using, ref, weak, union, async, do or goto, and the function list stops at a few of std/string.mxy and std/math.mxy. Add the missing words, and the functions from std/io.mxy, std/os.mxy and std/time.mxy. Keep hover text (lsp.mxy:183 onward) in step with what you add.

Edit this page on GitHub