diff --git a/lib/std/collections/anylist.c3 b/lib/std/collections/anylist.c3 index 30fb898fd..7ca04eb39 100644 --- a/lib/std/collections/anylist.c3 +++ b/lib/std/collections/anylist.c3 @@ -96,7 +96,7 @@ fn void AnyList.free_element(&self, any element) @inline Pop a value who's type is known. If the type is incorrect, this will still pop the element. - @return! TYPE_MISMATCH, NO_MORE_ELEMENT + @return? TYPE_MISMATCH, NO_MORE_ELEMENT *> macro AnyList.pop(&self, $Type) { @@ -107,7 +107,7 @@ macro AnyList.pop(&self, $Type) <* Pop the last value and allocate the copy using the given allocator. - @return! NO_MORE_ELEMENT + @return? NO_MORE_ELEMENT *> fn any? AnyList.copy_pop(&self, Allocator allocator) { @@ -119,13 +119,13 @@ fn any? AnyList.copy_pop(&self, Allocator allocator) <* Pop the last value and allocate the copy using the temp allocator - @return! NO_MORE_ELEMENT + @return? NO_MORE_ELEMENT *> fn any? AnyList.tcopy_pop(&self) => self.copy_pop(tmem()); <* Pop the last value. It must later be released using list.free_element() - @return! NO_MORE_ELEMENT + @return? NO_MORE_ELEMENT *> fn any? AnyList.pop_retained(&self) { diff --git a/lib/std/compression/qoi.c3 b/lib/std/compression/qoi.c3 index 00b55e658..02cba0ec7 100644 --- a/lib/std/compression/qoi.c3 +++ b/lib/std/compression/qoi.c3 @@ -94,7 +94,7 @@ fn usz? write(String filename, char[] input, QOIDesc* desc) => @pool() @param [in] filename : `The file's name to read the image from` @param [&out] desc : `The descriptor to fill with the image's info` @param channels : `The channels to be used` - @return! FILE_OPEN_FAILED, INVALID_DATA, TOO_MANY_PIXELS + @return? FILE_OPEN_FAILED, INVALID_DATA, TOO_MANY_PIXELS *> fn char[]? read(Allocator allocator, String filename, QOIDesc* desc, QOIChannels channels = AUTO) => @pool(allocator) { @@ -122,7 +122,7 @@ import std::bits; @param [in] input : `The raw RGB or RGBA pixels to encode` @param [&in] desc : `The descriptor of the image` - @return! INVALID_PARAMETERS, TOO_MANY_PIXELS, INVALID_DATA + @return? INVALID_PARAMETERS, TOO_MANY_PIXELS, INVALID_DATA *> fn char[]? encode(Allocator allocator, char[] input, QOIDesc* desc) @nodiscard { @@ -277,7 +277,7 @@ fn char[]? encode(Allocator allocator, char[] input, QOIDesc* desc) @nodiscard @param [in] data : `The QOI image data to decode` @param [&out] desc : `The descriptor to fill with the image's info` @param channels : `The channels to be used` - @return! INVALID_DATA, TOO_MANY_PIXELS + @return? INVALID_DATA, TOO_MANY_PIXELS *> fn char[]? decode(Allocator allocator, char[] data, QOIDesc* desc, QOIChannels channels = AUTO) @nodiscard { @@ -406,7 +406,7 @@ const char[*] END_OF_STREAM = {0, 0, 0, 0, 0, 0, 0, 1}; // inefficient, but it's only run once at a time <* - @return! INVALID_DATA + @return? INVALID_DATA *> macro @enumcast($Type, raw) { diff --git a/lib/std/core/allocators/arena_allocator.c3 b/lib/std/core/allocators/arena_allocator.c3 index 32a748984..672477dc6 100644 --- a/lib/std/core/allocators/arena_allocator.c3 +++ b/lib/std/core/allocators/arena_allocator.c3 @@ -57,7 +57,7 @@ fn void ArenaAllocator.reset(&self, usz mark) @dynamic => self.used = mark; @require !alignment || math::is_power_of_2(alignment) @require alignment <= mem::MAX_MEMORY_ALIGNMENT : `alignment too big` @require size > 0 - @return! mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY + @return? mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY *> fn void*? ArenaAllocator.acquire(&self, usz size, AllocInitType init_type, usz alignment) @dynamic { @@ -81,7 +81,7 @@ fn void*? ArenaAllocator.acquire(&self, usz size, AllocInitType init_type, usz a @require alignment <= mem::MAX_MEMORY_ALIGNMENT : `alignment too big` @require old_pointer != null @require size > 0 - @return! mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY + @return? mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY *> fn void*? ArenaAllocator.resize(&self, void *old_pointer, usz size, usz alignment) @dynamic { diff --git a/lib/std/core/allocators/dynamic_arena.c3 b/lib/std/core/allocators/dynamic_arena.c3 index 86963ab9b..5fd3ec751 100644 --- a/lib/std/core/allocators/dynamic_arena.c3 +++ b/lib/std/core/allocators/dynamic_arena.c3 @@ -78,7 +78,7 @@ fn void DynamicArenaAllocator.release(&self, void* ptr, bool) @dynamic @require size > 0 : `Resize doesn't support zeroing` @require old_pointer != null : `Resize doesn't handle null pointers` @require self.page != null : `tried to realloc pointer on invalid allocator` - @return! mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY + @return? mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY *> fn void*? DynamicArenaAllocator.resize(&self, void* old_pointer, usz size, usz alignment) @dynamic { @@ -130,7 +130,7 @@ fn void DynamicArenaAllocator.reset(&self, usz mark = 0) @dynamic <* @require math::is_power_of_2(alignment) @require size > 0 - @return! mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY + @return? mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY *> fn void*? DynamicArenaAllocator._alloc_new(&self, usz size, usz alignment) @local { @@ -161,7 +161,7 @@ fn void*? DynamicArenaAllocator._alloc_new(&self, usz size, usz alignment) @loca <* @require size > 0 : `acquire expects size > 0` @require !alignment || math::is_power_of_2(alignment) - @return! mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY + @return? mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY *> fn void*? DynamicArenaAllocator.acquire(&self, usz size, AllocInitType init_type, usz alignment) @dynamic { diff --git a/lib/std/core/array.c3 b/lib/std/core/array.c3 index ca0bce992..3c440266a 100644 --- a/lib/std/core/array.c3 +++ b/lib/std/core/array.c3 @@ -5,7 +5,7 @@ import std::core::array::slice; @param [in] array @param [in] element @return "the first index of the element" - @return! NOT_FOUND + @return? NOT_FOUND *> macro index_of(array, element) { @@ -34,7 +34,7 @@ macro slice2d(array_ptr, x = 0, xlen = 0, y = 0, ylen = 0) @param [in] array @param [in] element @return "the last index of the element" - @return! NOT_FOUND + @return? NOT_FOUND *> macro rindex_of(array, element) { diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 97fb66d7a..b550b9bb3 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -79,7 +79,7 @@ macro void @swap(#a, #b) @builtin @param $Type : `the type to convert to` @return `The any.ptr converted to its type.` @ensure @typeis(return, $Type*) - @return! TYPE_MISMATCH + @return? TYPE_MISMATCH *> macro anycast(any v, $Type) @builtin { @@ -247,7 +247,7 @@ macro bitcast(expr, $Type) @builtin @param [in] enum_name : `The name of the enum to search for` @require $Type.kindof == ENUM : `Only enums may be used` @ensure @typeis(return, $Type) - @return! NOT_FOUND + @return? NOT_FOUND *> macro enum_by_name($Type, String enum_name) @builtin { @@ -265,7 +265,7 @@ macro enum_by_name($Type, String enum_name) @builtin @require $defined($Type.#value) : `Expected '#value' to match an enum associated value` @require $assignable(value, $typeof(($Type){}.#value)) : `Expected the value to match the type of the associated value` @ensure @typeis(return, $Type) - @return! NOT_FOUND + @return? NOT_FOUND *> macro @enum_from_value($Type, #value, value) @builtin { diff --git a/lib/std/core/conv.c3 b/lib/std/core/conv.c3 index 83aa304ea..7ffbadf62 100644 --- a/lib/std/core/conv.c3 +++ b/lib/std/core/conv.c3 @@ -12,7 +12,7 @@ const uint UTF16_SURROGATE_HIGH_VALUE @private = 0xD800; <* @param c : `The utf32 codepoint to convert` @param [out] output : `the resulting buffer` - @return! string::CONVERSION_FAILED + @return? string::CONVERSION_FAILED *> fn usz? char32_to_utf8(Char32 c, char[] output) { diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index 4304f81e0..7279e95bd 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -24,7 +24,7 @@ interface Allocator @require !alignment || math::is_power_of_2(alignment) @require alignment <= mem::MAX_MEMORY_ALIGNMENT : `alignment too big` @require size > 0 - @return! mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY + @return? mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY *> fn void*? acquire(usz size, AllocInitType init_type, usz alignment = 0); <* @@ -32,7 +32,7 @@ interface Allocator @require alignment <= mem::MAX_MEMORY_ALIGNMENT : `alignment too big` @require ptr != null @require new_size > 0 - @return! mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY + @return? mem::INVALID_ALLOC_SIZE, mem::OUT_OF_MEMORY *> fn void*? resize(void* ptr, usz new_size, usz alignment = 0); <* diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 1dd2a8ed9..302daaadf 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -290,7 +290,7 @@ fault BUFFER_EXCEEDED; @param max : "Max number of elements, 0 means no limit, defaults to 0" @require needle.len > 0 : "The needle must be at least 1 character long" @ensure return.len > 0 - @return! BUFFER_EXCEEDED : `If there are more elements than would fit the buffer` + @return? BUFFER_EXCEEDED : `If there are more elements than would fit the buffer` *> fn String[]? String.split_to_buffer(s, String needle, String[] buffer, usz max = 0, bool skip_empty = false) { @@ -345,7 +345,7 @@ fn bool String.contains(s, String needle) @pure @ensure return < s.len @return "the index of the needle" - @return! NOT_FOUND : "if the needle cannot be found" + @return? NOT_FOUND : "if the needle cannot be found" *> fn usz? String.index_of_char(s, char needle) { @@ -364,7 +364,7 @@ fn usz? String.index_of_char(s, char needle) @pure @ensure return < s.len @return "the index of the needle" - @return! NOT_FOUND : "if the needle cannot be found" + @return? NOT_FOUND : "if the needle cannot be found" *> fn usz? String.index_of_chars(String s, char[] needle) { @@ -388,7 +388,7 @@ fn usz? String.index_of_chars(String s, char[] needle) @pure @ensure return < s.len @return "the index of the needle" - @return! NOT_FOUND : "if the needle cannot be found starting from the start_index" + @return? NOT_FOUND : "if the needle cannot be found starting from the start_index" *> fn usz? String.index_of_char_from(s, char needle, usz start_index) { @@ -409,7 +409,7 @@ fn usz? String.index_of_char_from(s, char needle, usz start_index) @pure @ensure return < s.len @return "the index of the needle" - @return! NOT_FOUND : "if the needle cannot be found" + @return? NOT_FOUND : "if the needle cannot be found" *> fn usz? String.rindex_of_char(s, char needle) { @@ -429,7 +429,7 @@ fn usz? String.rindex_of_char(s, char needle) @ensure return < s.len @require needle.len > 0 : "The needle must be len 1 or more" @return "the index of the needle" - @return! NOT_FOUND : "if the needle cannot be found" + @return? NOT_FOUND : "if the needle cannot be found" *> fn usz? String.index_of(s, String needle) { @@ -454,7 +454,7 @@ fn usz? String.index_of(s, String needle) @ensure return < s.len @require needle.len > 0 : "The needle must be len 1 or more" @return "the index of the needle" - @return! NOT_FOUND : "if the needle cannot be found" + @return? NOT_FOUND : "if the needle cannot be found" *> fn usz? String.rindex_of(s, String needle) { @@ -556,7 +556,7 @@ fn String ZString.tcopy(z) <* Convert an UTF-8 string to UTF-16 @return "The UTF-16 string as a slice, allocated using the given allocator" - @return! INVALID_UTF8 : "If the string contained an invalid UTF-8 sequence" + @return? INVALID_UTF8 : "If the string contained an invalid UTF-8 sequence" *> fn Char16[]? String.to_utf16(s, Allocator allocator) { diff --git a/lib/std/encoding/base32.c3 b/lib/std/encoding/base32.c3 index 7a9296196..912716982 100644 --- a/lib/std/encoding/base32.c3 +++ b/lib/std/encoding/base32.c3 @@ -84,7 +84,7 @@ fn usz encode_len(usz n, char padding) @require padding < 0xFF : "Invalid padding character" @require dst.len >= decode_len(src.len, padding) : "Destination buffer too small" @return "The resulting dst buffer" - @return! encoding::INVALID_PADDING, encoding::INVALID_CHARACTER + @return? encoding::INVALID_PADDING, encoding::INVALID_CHARACTER *> fn char[]? decode_buffer(char[] src, char[] dst, char padding = DEFAULT_PAD, Base32Alphabet* alphabet = &STANDARD) { diff --git a/lib/std/encoding/base64.c3 b/lib/std/encoding/base64.c3 index e5e8c64e1..4bb6ef92a 100644 --- a/lib/std/encoding/base64.c3 +++ b/lib/std/encoding/base64.c3 @@ -79,7 +79,7 @@ fn usz encode_len(usz n, char padding) @param padding : "The padding character or 0 if none" @require padding < 0xFF : "Invalid padding character" @return "The size of the input once decoded." - @return! encoding::INVALID_PADDING + @return? encoding::INVALID_PADDING *> fn usz? decode_len(usz n, char padding) { @@ -163,7 +163,7 @@ fn String encode_buffer(char[] src, char[] dst, char padding = DEFAULT_PAD, Base @require (decode_len(src.len, padding) ?? 0) <= dst.len : "Destination buffer too small" @require padding < 0xFF : "Invalid padding character" @return "The decoded data." - @return! encoding::INVALID_CHARACTER, encoding::INVALID_PADDING + @return? encoding::INVALID_CHARACTER, encoding::INVALID_PADDING *> fn char[]? decode_buffer(char[] src, char[] dst, char padding = DEFAULT_PAD, Base64Alphabet* alphabet = &STANDARD) { diff --git a/lib/std/encoding/hex.c3 b/lib/std/encoding/hex.c3 index be6b24d79..6e528ed3e 100644 --- a/lib/std/encoding/hex.c3 +++ b/lib/std/encoding/hex.c3 @@ -72,7 +72,7 @@ macro usz decode_len(usz n) => n / 2; @param dst : "The decoded input." @require src.len % 2 == 0 : "src is not of even length" @require dst.len >= decode_len(src.len) : "Destination array is not large enough" - @return! encoding::INVALID_CHARACTER + @return? encoding::INVALID_CHARACTER *> fn usz? decode_bytes(char[] src, char[] dst) { diff --git a/lib/std/io/path.c3 b/lib/std/io/path.c3 index de2d41530..e5904e82e 100644 --- a/lib/std/io/path.c3 +++ b/lib/std/io/path.c3 @@ -109,7 +109,7 @@ macro bool? mkdir(Path path, bool recursive = false, MkdirPermissions permission @param path : `The path to delete` @require @is_pathlike(path) : "Expected a Path or String to chdir" @return `true if there was a directory to delete, false otherwise` - @return! INVALID_PATH : `if the path was invalid` + @return? INVALID_PATH : `if the path was invalid` *> macro bool? rmdir(path) { @@ -136,7 +136,7 @@ fn void? rmtree(Path path) <* Creates a new path. - @return! INVALID_PATH : `if the path was invalid` + @return? INVALID_PATH : `if the path was invalid` *> fn Path? new(Allocator allocator, String path, PathEnv path_env = DEFAULT_ENV) { @@ -146,7 +146,7 @@ fn Path? new(Allocator allocator, String path, PathEnv path_env = DEFAULT_ENV) <* Creates a new path using the temp allocator. - @return! INVALID_PATH : `if the path was invalid` + @return? INVALID_PATH : `if the path was invalid` *> fn Path? temp(String path, PathEnv path_env = DEFAULT_ENV) { @@ -391,7 +391,7 @@ fn usz? volume_name_len(String path, PathEnv path_env) @local of the path itself. @return `The parent of the path as a non-allocated path` - @return! NO_PARENT : `if this path does not have a parent` + @return? NO_PARENT : `if this path does not have a parent` *> fn Path? Path.parent(self) { diff --git a/lib/std/net/url_encoding.c3 b/lib/std/net/url_encoding.c3 index 48ef50f57..fa506d6a4 100644 --- a/lib/std/net/url_encoding.c3 +++ b/lib/std/net/url_encoding.c3 @@ -105,7 +105,7 @@ fn String tencode(String s, UrlEncodingMode mode) => encode(tmem(), s, mode); <* Calculate the length of the percent-decoded string. - @return! INVALID_HEX + @return? INVALID_HEX *> fn usz? decode_len(String s, UrlEncodingMode mode) @inline { diff --git a/lib/std/os/env.c3 b/lib/std/os/env.c3 index 2726bf924..2f0cf02ba 100644 --- a/lib/std/os/env.c3 +++ b/lib/std/os/env.c3 @@ -7,7 +7,7 @@ import std::io::path, libc, std::os; <* @param [in] name @require name.len > 0 - @return! NOT_FOUND + @return? NOT_FOUND *> fn String? get_var(Allocator allocator, String name) => @pool(allocator) { diff --git a/releasenotes.md b/releasenotes.md index e14a9450a..2314fe714 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -22,7 +22,7 @@ - `$for` "()" replaced by trailing ":" `$for (var $x = 0; $x < FOO; $x++)` -> `$for var $x = 0; $x < FOO; $x++:` - `$switch` "()" replaced by trailing ":" `$switch ($Type)` -> `$switch $Type:` - Empty `$switch` requires trailing ":" `$switch` -> `$switch:` -- Change `@return!` syntax to require ":" after faults. +- Rename `@return` to `@return?` and change syntax to require ":" after faults. - Remove `if (catch foo) { case ... }` syntax. - Remove `[?]` syntax. - Change `int!` to `int?` syntax. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index a324c5243..c7b9f21d8 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -2770,7 +2770,7 @@ static bool parse_contracts(ParseContext *c, AstId *contracts_ref) else if (name == kw_at_return) { advance(c); - if (tok_is(c, TOKEN_BANG)) + if (tok_is(c, TOKEN_QUESTION)) { if (!parse_doc_optreturn(c, contracts_ref, next)) return false; } diff --git a/test/test_suite/errors/optional_contracts.c3 b/test/test_suite/errors/optional_contracts.c3 index 00cef7e58..1c89ed6a3 100644 --- a/test/test_suite/errors/optional_contracts.c3 +++ b/test/test_suite/errors/optional_contracts.c3 @@ -8,7 +8,7 @@ fault XYZ; <* hello world - @return! XYZ, ABC + @return? XYZ, ABC *> fn void? abc(int a, int b, int z) { @@ -17,7 +17,7 @@ fn void? abc(int a, int b, int z) <* hello world - @return! XYZ, ABC + @return? XYZ, ABC *> macro void? @abc(int a, int b, int z) {