-
-
Notifications
You must be signed in to change notification settings - Fork 329
Open
Labels
Semantic AnalysisChanges to semantic behaviour, including compile time folding.Changes to semantic behaviour, including compile time folding.
Milestone
Description
When using List{String} and defining a method on the alias, the compiler errors out in types::is_equatable_type because top‑level tests for the presence of methods via $defined run before method registration is complete.
Minimal example:
import std::collections;
fn int main() => 0;
alias StringList = List{String};
fn void StringList.foo(&self) {}Error:
345:
346: macro bool is_equatable_type($Type) @const
347: {
348: $if $defined($Type.less) || $defined($Type.compare_to) || $defined($Type.equals):
^^^^^^^^^^
(../c3c/lib/std/core/types.c3:348:15) Error: There might be a method 'less' for 'String', but methods for the type have not yet been completely registered, so this yields an error.
6:
7: alias ElementPredicate = fn bool(Type *type);
8: alias ElementTest = fn bool(Type *type, any context);
9: const ELEMENT_IS_EQUATABLE = types::is_equatable_type(Type);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If a less method is added to String to satisfy the first check, the error simply shifts to compare_to, then to equals, until all three methods exist, even though the macro’s intent is just to probe for whichever methods are present.
Observed behavior:
- Top‑level
$defined($Type.method)checks are evaluated while method registration is still incomplete forType(here:String). - As a result, the compiler reports that such checks are prohibited “previous to method registration”, and the only way to make the code compile is to implement all methods that the macro might look for.
- Commit that introduced the observed behavior was 18b246c5 ("Testing for the presence of methods at the top level is prohibited previous to method registration.").
Expected behavior:
- Top‑level uses that depend on method presence (like
is_equatable_type) should not fail just because the relevant methods have not yet been registered at that point. - It should be possible to use
List{String}and define methods on the alias without being forced to implement all candidate comparison methods onString.
Possible direction / idea:
One possible solution would be to lazily evaluate top‑level constructs:
- If a top‑level entity
Xneeds information fromY, andYhas not been fully evaluated/registered yet, defer evaluation ofXinstead of erroring. - In this example, evaluation of
types::is_equatable_type(String)could be deferred until method registration forStringis complete, allowing$defined($Type.less|compare_to|equals)to work as intended.
Compiler version:
C3 Compiler Version: 0.7.9 (Pre-release, Jan 28 2026 14:53:47)
Git Hash: a07660f957d5f68a46669c4244592e0cae605693
Backends: LLVM
LLVM version: 18.1.8
LLVM default target: x86_64-pc-linux-gnu
Metadata
Metadata
Assignees
Labels
Semantic AnalysisChanges to semantic behaviour, including compile time folding.Changes to semantic behaviour, including compile time folding.