mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Show error when declarations do not start with fn in interfaces. #1565. Some added functionality to lists and time.
This commit is contained in:
@@ -245,6 +245,11 @@ fn Type! LinkedList.pop(&self)
|
|||||||
return self._last.value;
|
return self._last.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bool LinkedList.is_empty(&self)
|
||||||
|
{
|
||||||
|
return !self._first;
|
||||||
|
}
|
||||||
|
|
||||||
fn Type! LinkedList.pop_front(&self)
|
fn Type! LinkedList.pop_front(&self)
|
||||||
{
|
{
|
||||||
if (!self._first) return IteratorResult.NO_MORE_ELEMENT?;
|
if (!self._first) return IteratorResult.NO_MORE_ELEMENT?;
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ fn void PrivatePriorityQueue.temp_init(&self, usz initial_capacity = 16) @inline
|
|||||||
self.heap.new_init(initial_capacity, allocator::temp()) @inline;
|
self.heap.new_init(initial_capacity, allocator::temp()) @inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn void PrivatePriorityQueue.push(&self, Type element)
|
fn void PrivatePriorityQueue.push(&self, Type element)
|
||||||
{
|
{
|
||||||
self.heap.push(element);
|
self.heap.push(element);
|
||||||
@@ -66,6 +67,15 @@ fn void PrivatePriorityQueue.push(&self, Type element)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn void PrivatePriorityQueue.remove_at(&self, usz index)
|
||||||
|
{
|
||||||
|
if (index == 0)
|
||||||
|
{
|
||||||
|
self.pop()!!;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.heap.remove_at(index);
|
||||||
|
}
|
||||||
<*
|
<*
|
||||||
@require self != null
|
@require self != null
|
||||||
*>
|
*>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ distinct Duration = long;
|
|||||||
distinct Clock = ulong;
|
distinct Clock = ulong;
|
||||||
distinct NanoDuration (Printable) = long;
|
distinct NanoDuration (Printable) = long;
|
||||||
|
|
||||||
|
const Time FAR_FUTURE = long.max;
|
||||||
|
const Time FAR_PAST = long.min;
|
||||||
const Duration US = 1;
|
const Duration US = 1;
|
||||||
const Duration MS = 1_000;
|
const Duration MS = 1_000;
|
||||||
const Duration SEC = 1_000_000;
|
const Duration SEC = 1_000_000;
|
||||||
@@ -15,6 +17,7 @@ const Duration DAY = 24 * HOUR;
|
|||||||
const Duration WEEK = 7 * DAY;
|
const Duration WEEK = 7 * DAY;
|
||||||
const Duration MONTH = 30 * DAY;
|
const Duration MONTH = 30 * DAY;
|
||||||
const Duration YEAR = 36525 * DAY / 100;
|
const Duration YEAR = 36525 * DAY / 100;
|
||||||
|
const Duration FOREVER = long.max;
|
||||||
|
|
||||||
fn Duration us(long l) @inline => (Duration)l * US;
|
fn Duration us(long l) @inline => (Duration)l * US;
|
||||||
fn Duration ms(long l) @inline => (Duration)l * MS;
|
fn Duration ms(long l) @inline => (Duration)l * MS;
|
||||||
@@ -86,6 +89,13 @@ fn Time Time.add_hours(time, long hours) => time + (Time)(hours * (long)HOUR);
|
|||||||
fn Time Time.add_days(time, long days) => time + (Time)(days * (long)DAY);
|
fn Time Time.add_days(time, long days) => time + (Time)(days * (long)DAY);
|
||||||
fn Time Time.add_weeks(time, long weeks) => time + (Time)(weeks * (long)WEEK);
|
fn Time Time.add_weeks(time, long weeks) => time + (Time)(weeks * (long)WEEK);
|
||||||
fn Time Time.add_duration(time, Duration duration) => time + (Time)duration;
|
fn Time Time.add_duration(time, Duration duration) => time + (Time)duration;
|
||||||
|
|
||||||
|
fn int Time.compare_to(time, Time other)
|
||||||
|
{
|
||||||
|
if (time == other) return 0;
|
||||||
|
return time > other ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
fn double Time.to_seconds(time) => (long)time / (double)SEC;
|
fn double Time.to_seconds(time) => (long)time / (double)SEC;
|
||||||
fn Duration Time.diff_us(time, Time other) => (Duration)(time - other);
|
fn Duration Time.diff_us(time, Time other) => (Duration)(time - other);
|
||||||
fn double Time.diff_sec(time, Time other) => (long)time.diff_us(other) / (double)SEC;
|
fn double Time.diff_sec(time, Time other) => (long)time.diff_us(other) / (double)SEC;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
- Wrong error message for interface methods with body #1536.
|
- Wrong error message for interface methods with body #1536.
|
||||||
- Empty expression block would crash compiler with debug on #1554.
|
- Empty expression block would crash compiler with debug on #1554.
|
||||||
- Improve infer conversions on constants, e.g. `ZString a = foo ? "a" : "b";` #1561
|
- Improve infer conversions on constants, e.g. `ZString a = foo ? "a" : "b";` #1561
|
||||||
|
- Show error when declarations do not start with `fn` in interfaces. #1565
|
||||||
|
|
||||||
### Stdlib changes
|
### Stdlib changes
|
||||||
- Remove unintended print of `char[]` as String
|
- Remove unintended print of `char[]` as String
|
||||||
|
|||||||
@@ -1770,6 +1770,10 @@ INLINE bool parse_interface_body(ParseContext *c, Decl *interface)
|
|||||||
{
|
{
|
||||||
AstId contracts = 0;
|
AstId contracts = 0;
|
||||||
if (!parse_contracts(c, &contracts)) return poisoned_decl;
|
if (!parse_contracts(c, &contracts)) return poisoned_decl;
|
||||||
|
if (!tok_is(c, TOKEN_FN))
|
||||||
|
{
|
||||||
|
RETURN_PRINT_ERROR_HERE("Interfaces can only have function declarations, and they must start with 'fn' as usual.");
|
||||||
|
}
|
||||||
ASSIGN_DECL_OR_RET(Decl *interface_fn, parse_func_definition(c, contracts, FUNC_PARSE_INTERFACE), false);
|
ASSIGN_DECL_OR_RET(Decl *interface_fn, parse_func_definition(c, contracts, FUNC_PARSE_INTERFACE), false);
|
||||||
vec_add(fns, interface_fn);
|
vec_add(fns, interface_fn);
|
||||||
}
|
}
|
||||||
|
|||||||
4
test/test_suite/any/interface_no_fn.c3
Normal file
4
test/test_suite/any/interface_no_fn.c3
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
interface IOp {
|
||||||
|
int val; // #error: Interfaces can only have function
|
||||||
|
int my_fn(); // missing fn
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user