Baseline: tree as shared

This commit is contained in:
alexm committed 2026-10-05 03:03:38 +00:00
commit 659c03bbf8
1471 files changed
+990535

No files matched your search

@@ -0,0 +1,51 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen %s -elaborate -verify-diagnostics
# expected-error @+2{{function instantiation failed}}
@export
def wrong_attribute_name(a: Int, b: Int) abi("Mojo") raises -> Bool:
comptime pred_attr = __mlir_attr.`#index.cmp_predicate<sle>`
# expected-note @below {{unexpected attribute 'foobar' on operation}}
var res = __mlir_op.`index.cmp`[foobar=pred_attr](a, b)
return res
# expected-error @+2{{function instantiation failed}}
@export
def extra_attribute(a: Int, b: Int) abi("Mojo") raises -> Bool:
comptime pred_attr = __mlir_attr.`#index.cmp_predicate<sle>`
# expected-note @below {{unexpected attribute 'foobar' on operation}}
var res = __mlir_op.`index.cmp`[pred=pred_attr, foobar=pred_attr](
a.__mlir_index__(), b.__mlir_index__()
)
return res
# expected-error @+2{{function instantiation failed}}
@export
def invalid_predicate_passed(x: Int, y: Int) abi("Mojo") -> Bool:
def pred() -> __mlir_type.`!kgen.string`:
return __mlir_attr[`"xyz" : !kgen.string`]
def get_pred() -> __mlir_type.`!kgen.deferred`:
return __mlir_deferred_attr[`#index.cmp_predicate<`, pred(), `>`]
# expected-note @below {{invalid MLIR attribute: failed to parse IndexCmpPredicateAttr parameter 'value' which is to be a `::mlir::index::IndexCmpPredicate`}}
var z = __mlir_op.`index.cmp`[pred=get_pred()](x, y)
return z
@@ -0,0 +1,39 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen %s -elaborate -verify-diagnostics
# Counterpart to callback_inferred_addrspace.mojo: there the deferred type stays
# abstract (an escaping parameter reference) so the materialization error is
# suppressed. Here the parameter `n` is fully bound at materialization, leaving
# no escaping reference, but the resulting concrete type string is unparseable.
# The "invalid MLIR type in deferred_type" error must fire.
@no_inline
def use[
n: Int
]() -> __mlir_deferred_type[`!llvm.array<`, +n.__mlir_index__(), ` bogus f32>`]:
return __mlir_op.`llvm.mlir.undef`[
_type=__mlir_deferred_type[
`!llvm.array<`, +n.__mlir_index__(), ` bogus f32>`
]
]()
# expected-error @+1 {{function instantiation failed}}
def main():
comptime sz: Int = 4
# expected-note @+1 {{invalid MLIR type in deferred_type: !llvm.array<4 bogus f32>}}
_ = use[sz]()
print("ok")
@@ -0,0 +1,143 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen %s -elaborate=no-use-parametric-interpreter -verify-diagnostics
# RUN: not kgen -elaborate -D TEST_RECURSION2=1 %s 2>&1 | FileCheck %s --check-prefix=CHECK-RECURSION2
# RUN: not kgen -elaborate -D TEST_RECURSION3=1 %s 2>&1 | FileCheck %s --check-prefix=CHECK-RECURSION3
from std.collections.string.string_span import StaticString, _get_kgen_string
from std.sys import get_defined_bool
# expected-error @+2{{function instantiation failed}}
@export
def entry_method() abi("Mojo"):
foo() # expected-note {{call expansion failed}}
@always_inline("nodebug")
def foo():
bar() # expected-note {{call expansion failed}}
@always_inline("nodebug")
def bar():
baz() # expected-note {{call expansion failed}}
@always_inline("nodebug")
def baz():
__mlir_op.`kgen.param.assert`[
cond=__mlir_attr.`#kgen.simd<false> : !kgen.scalar<bool>`,
message="oops".value,
]() # expected-note {{constraint failed}}
# expected-error @+2{{function instantiation failed}}
@export
def test_no_params() abi("Mojo"):
no_parameters() # expected-note {{call expansion failed}}
# expected-note @+2{{function instantiation failed}}
@no_inline
def no_parameters():
parametric[1]() # expected-note {{call expansion failed}}
@no_inline
def parametric[param: Int](): # expected-note {{function instantiation failed}}
comptime assert ( # expected-note {{constraint failed: param must be 2}}
param == 2
), "param must be 2"
# This is copied so the note ends up in this file.
@always_inline("nodebug")
def constrained[cond: Bool, msg: StaticString]():
comptime msg_literal = _get_kgen_string[msg]()
__mlir_op.`kgen.param.assert`[
cond=cond.__mlir_bool__(), message=msg_literal
]()
# expected-error @+2{{function instantiation failed}}
@export
def test_comptime_assert() abi("Mojo"):
parametric_assert[1]() # expected-note {{call expansion failed}}
# expected-note @+2{{function instantiation failed}}
@no_inline
def parametric_assert[param: Int]():
# expected-note @below {{constraint failed: param must be 2}}
comptime assert param == 2, "param must be 2"
# This creates recursive cycles: foo[D] -> bar[D] -> foo[D] and foo[D] -> baz[D] -> foo[D]
def bar[D: Int]() -> Int:
comptime x = foo[D]()
return x
def baz[D: Int]() -> Int:
comptime x = foo[D]()
return x
def foo[D: Int]() -> Int:
var x = bar[D]()
# CHECK-RECURSION2: call expansion failed with parameter value(s): ("D": 2)
var y = baz[D]()
_ = x
_ = y
return y
def test_recursion2():
comptime run_test = get_defined_bool["TEST_RECURSION2", False]()
comptime if run_test:
# CHECK-RECURSION2: call expansion failed with parameter value(s): ("D": 2)
_ = foo[2]()
# CHECK-RECURSION2: function instantiation in parameter domain that recursively requires itself
# CHECK-RECURSION2: recursively instantiated through here
# This creates a recursive cycle: foo1[D] -> bar1[D] -> foo1[D]
def bar1[D: Int]() -> Int:
comptime x = foo1[D]()
return x
def foo1[D: Int]() -> Int:
# CHECK-RECURSION3: call expansion failed with parameter value(s): ("D": 1)
var x = bar1[D]()
return x
def test_recursion3():
comptime run_test = get_defined_bool["TEST_RECURSION3", False]()
comptime if run_test:
# CHECK-RECURSION3: call expansion failed with parameter value(s): ("D": 1)
_ = foo1[1]()
# CHECK-RECURSION3: function instantiation in parameter domain that recursively requires itself
# CHECK-RECURSION3: recursively instantiated through here
def main():
test_recursion2()
test_recursion3()
@@ -0,0 +1,71 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen %s -elaborate -elaboration-error-limit=2 --num-threads=1 -verify-diagnostics
# RUN: not kgen %s -elaborate=use-parametric-interpreter -elaboration-error-limit=2 --num-threads=1 2>&1 | FileCheck %s --check-prefix=CHECK-PARAM
# COM: -elaborate=use-parametric-interpreter slight difference from -elaborate for error messages.
# Using FileCheck instead to check those with CHECK-PRAMA prefix.
# (TODO) error message for parametric interpreter is non-deterministic with limit=2, i.e.
# either combination of 2 out of foo, bar and baz can show up, hence not checking with a label
# expected-error @+2{{function instantiation failed}}
@export
def entry_method0() abi("Mojo"):
foo() # expected-note {{call expansion failed}}
# expected-error @+3{{function instantiation failed}}
# expected-note @+2{{too many errors emitted, stopping now}}
@export
def entry_method1() abi("Mojo"):
bar() # expected-note {{call expansion failed}}
@export
def entry_method2() abi("Mojo"):
baz()
# expected-note @+2{{function instantiation failed}}
@no_inline
def foo():
__mlir_op.`kgen.param.assert`[
cond=__mlir_attr.`#kgen.simd<false> : !kgen.scalar<bool>`,
message="oops".value,
]() # expected-note {{constraint failed}}
# CHECK-PARAM: function instantiation failed
# CHECK-PARAM: constraint failed
# expected-note @+2 {{function instantiation failed}}
@no_inline
def bar():
__mlir_op.`kgen.param.assert`[
cond=__mlir_attr.`#kgen.simd<false> : !kgen.scalar<bool>`,
message="oops".value,
]() # expected-note {{constraint failed}}
# CHECK-PARAM: function instantiation failed
# CHECK-PARAM: constraint failed
@no_inline
def baz():
__mlir_op.`kgen.param.assert`[
cond=__mlir_attr.`#kgen.simd<false> : !kgen.scalar<bool>`,
message="oops".value,
]()
# CHECK-PARAM: too many errors emitted, stopping now
@@ -0,0 +1,53 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen -elaborate %s --verify-diagnostics
# RUN: not kgen -elaborate %s --elaboration-error-include-prelude 2>&1 | FileCheck %s --check-prefix=CHECK-PRELUDE
# RUN: not mojo --elaboration-error-include-prelude %s 2>&1 | FileCheck %s --check-prefix=CHECK-PRELUDE
# RUN: not kgen -elaborate %s --elaboration-error-include-prelude --elaboration-error-verbose=all-params 2>&1 | FileCheck %s --check-prefix=CHECK-VERBOSE
# RUN: not mojo --elaboration-error-include-prelude --elaboration-error-verbose=all-params %s 2>&1 | FileCheck %s --check-prefix=CHECK-VERBOSE
from std.collections.string.string_span import _get_kgen_string
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: error: function instantiation failed
# CHECK-VERBOSE: {{.*}}std/builtin/_startup.mojo
# CHECK-VERBOSE-SAME: error: function instantiation failed
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: note: call expansion failed with parameter value(s): (...)
# CHECK-VERBOSE: {{.*}}std/builtin/_startup.mojo
# CHECK-VERBOSE-SAME: note: call expansion failed with parameter value(s): ("main_func":
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: note: function instantiation failed
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: note: call expansion failed
@always_inline("nodebug")
def my_constrained[cond: Bool, msg: StaticString, *extra: StaticString]():
__mlir_op.`kgen.param.assert`[
cond=cond.__mlir_bool__(),
message=_get_kgen_string[msg, *extra](),
]() # expected-note {{constraint failed}}
# expected-note @below {{function instantiation failed}}
def my_func():
# expected-note @below {{call expansion failed}}
my_constrained[False, "foo"]()
# expected-error @below {{function instantiation failed}}
def main():
# expected-note @below {{call expansion failed}}
my_func()
@@ -0,0 +1,47 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen -elaborate %s --verify-diagnostics
# RUN: not kgen -elaborate %s --elaboration-error-include-prelude 2>&1 | FileCheck %s --check-prefix=CHECK-PRELUDE
# RUN: not mojo --elaboration-error-include-prelude %s 2>&1 | FileCheck %s --check-prefix=CHECK-PRELUDE
from std.collections.string.string_span import _get_kgen_string
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: error: function instantiation failed
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: note: call expansion failed
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: note: function instantiation failed
# CHECK-PRELUDE: {{.*}}std/builtin/_startup.mojo
# CHECK-PRELUDE-SAME: note: call expansion failed
@always_inline("nodebug")
def my_constrained[cond: Bool, msg: StaticString, *extra: StaticString]():
__mlir_op.`kgen.param.assert`[
cond=cond.__mlir_bool__(),
message=_get_kgen_string[msg, *extra](),
]() # expected-note {{constraint failed}}
# expected-note @below {{function instantiation failed}}
def my_func():
# expected-note @below {{call expansion failed}}
my_constrained[False, "foo"]()
# expected-error @below {{function instantiation failed}}
def main():
# expected-note @below {{call expansion failed}}
my_func()
@@ -0,0 +1,40 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen -elaborate -elaboration-max-depth=128 --elaboration-error-verbose=no-params %s --verify-diagnostics
# RUN: not mojo build -elaboration-max-depth=128 --elaboration-error-verbose=no-params %s 2>&1 | FileCheck %s
from std.collections.string.string_span import _get_kgen_string
from std.sys import get_defined_bool
# expected-note @below {{function instantiation failed}}
# expected-note @below {{remaining errors after}}
# expected-note-re @below {{error recurses {{[0-9]+}} times}}
# expected-note-re @below {{elaborator expansion is {{[0-9]+}} levels deep - infinite recursion?}}
def self_recursion[i: Int]() -> Int:
# expected-note @below {{call expansion failed}}
# expected-warning @below {{self recursive call will cause an infinite loop}}
var x = self_recursion[i + 1]()
return x
# expected-error @below {{function instantiation failed}}
def main():
# expected-note @below {{call expansion failed}}
_ = self_recursion[1]()
# CHECK: self recursive call will cause an infinite loop
# CHECK: error recurses {{[0-9]+}} times
# CHECK: elaborator expansion is {{[0-9]+}} levels deep - infinite recursion?
@@ -0,0 +1,38 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen -elaborate %s --verify-diagnostics
# This creates a recursive cycle: foo[D] -> bar[D] -> foo[D]
# expected-note @below {{function instantiation failed}}
# expected-note @below {{function instantiation in parameter domain that recursively requires itself}}
# expected-note @below {{back to parameter domain function call here}}
def bar[D: Int]() -> Int:
comptime x = foo[D]()
return x
# expected-note @below {{function instantiation failed}}
def foo[D: Int]() -> Int:
# expected-note @below {{recursively instantiated through here}}
# expected-note @below {{call expansion failed with parameter value(s): ("D": 1)}}
var x = bar[D]()
return x
# expected-error @below {{function instantiation failed}}
def main():
# expected-note @below {{call expansion failed with parameter value(s): ("D": 1)}}
_ = foo[1]()
@@ -0,0 +1,45 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen -elaborate %s --verify-diagnostics
# This creates recursive cycles: foo[D] -> bar[D] -> foo[D] and foo[D] -> baz[D] -> foo[D]
# expected-note @below {{recursively instantiated through here}}
def bar[D: Int]() -> Int:
comptime x = foo[D]()
return x
# expected-note @below {{function instantiation failed}}
# expected-note @below {{function instantiation in parameter domain that recursively requires itself}}
def baz[D: Int]() -> Int:
comptime x = foo[D]()
return x
# expected-note @below {{function instantiation failed}}
def foo[D: Int]() -> Int:
# expected-note @below {{recursively instantiated through here}}
var x = bar[D]()
# expected-note @below {{call expansion failed with parameter value(s): ("D": 2)}}
var y = baz[D]()
_ = x
_ = y
return y
# expected-error @below {{function instantiation failed}}
def main():
# expected-note @below {{call expansion failed with parameter value(s): ("D": 2)}}
_ = foo[2]()
@@ -0,0 +1,36 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen -elaborate %s --verify-diagnostics
# Every generator in this cycle is trivial enough for `ApplyInliner` to give it
# an inlined form: the body is just a parameter constant and a return. That form
# then applies the generator it came from, so expanding it re-derives the same
# apply forever and used to overflow the stack before the elaborator ever saw
# the cycle. The sibling recursion tests route their cycle through a generator
# holding a runtime call, which never gets an inlined form, so the expansion has
# nothing to loop on there. See MOCO-4518.
# expected-note @below {{function instantiation failed}}
# expected-note @below {{function instantiation in parameter domain that recursively requires itself}}
# expected-note @below {{function recursively calls itself in the parameter domain}}
def g[n: Int]() -> Int:
comptime m = g[n]()
return m
# expected-error @below {{function instantiation failed}}
def main():
# expected-note @below {{call expansion failed with parameter value(s): ("n": 1)}}
print(g[1]())
@@ -0,0 +1,56 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen -elaborate %s --verify-diagnostics
# Verifies that a type error inside a mutually
# recursive function (an elaboration SCC) is surfaced through the SCC boundary
# to the caller.
# expected-note @below {{function instantiation failed}}
def check_allowed[T: AnyType]():
comptime assert ( # expected-note {{constraint failed: type not allowed}}
False
), "type not allowed"
trait Visitor:
def visit(self, x: Int) raises -> Int:
return 0
# expected-note @below {{function instantiation failed}}
def dispatch[V: Visitor](v: V, x: Int) raises -> Int:
# expected-note @below {{call expansion failed}}
return v.visit(x)
struct BadVisitor(Visitor):
def __init__(out self):
pass
# expected-note @below {{function instantiation failed}}
def visit(self, x: Int) raises -> Int:
# dispatch(self, x) is the intra-SCC back-edge and is not in the chain.
_ = dispatch(self, x)
# expected-note @below {{call expansion failed}}
check_allowed[String]()
return 0
# expected-error @below {{function instantiation failed}}
def main() raises:
var v = BadVisitor()
# expected-note @below {{call expansion failed with parameter value(s): (...)}}
_ = dispatch(v, 1)
@@ -0,0 +1,95 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
def fn_missing_constraint[n: Int]() where n > 0:
pass
def overloaded_function(n: Int):
pass
def overloaded_function(n: Float64):
pass
def overloaded_function(n: Int, m: Float64):
pass
@fieldwise_init
struct PosOnlyStruct[a: Int, b: Int, /, c: Int = 9]:
pass
struct DeprecatedImplicitConversion:
@implicit(deprecated=True)
def __init__(out self, value: Int):
pass
@always_inline("builtin")
def foldable_predicate(y: Int) -> Bool:
return y > 10
def constraint_fn[a: Int, b: Int]() where a > 0:
pass
def unfoldable_predicate(y: Int) -> Bool:
return y > 2
def unprovable_constraints[x: Int]() where unfoldable_predicate(x):
pass
struct Conflict:
pass
trait ConflictTraitName:
def test[a: Int](self):
pass
trait NoDefaultFunc:
def doSomething(self):
...
trait StillNoDefaultFunc(NoDefaultFunc):
def doEverything(self):
...
trait UnprovableCandidateTrait:
# expected-note @below {{required by trait method here}}
def handle(self):
...
trait ConflictTraitMethod:
def test(self) -> Bool:
return True
trait OtherConflictTraitMethod(ConflictTraitMethod):
def test(self) -> Bool:
return False
trait TraitWithMember:
comptime N: Int
@@ -0,0 +1,22 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2026, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# RUN: kgen %s -elaborate -verify-diagnostics
@export
def origins_dont_exist_at_elaboration_time(
a: String, b: String
) abi("Mojo") -> Bool:
# expected-error @+1 {{origin equality may only be tested in 'where' clauses}}
return origin_of(b).contains[origin_of(a)]