Skip to content

Commit

Permalink
[stdlib] Add implicit decorators to constructors, NFC
Browse files Browse the repository at this point in the history
This adds `@implicit` to all single-argument constructors to enable
explicit by default construction. Implicit conversions are used heavily
throughout the codebase, and so this is a required step to get it to
compile. This allows us to take off `@implicit` constructors where
they don't make sense, and fix the compiler errors one step at
a time.

MODULAR_ORIG_COMMIT_REV_ID: 931a2f38a0f9fe87007e334158f1fdf399f04bb2

Signed-off-by: Manuel Saelices <msaelices@gmail.com>
  • Loading branch information
jackos authored and msaelices committed Nov 22, 2024
1 parent 1f73704 commit 43fa507
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/src/builtin/object.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ struct object(
# FIXME: None literal should be of NoneType not !kgen.none.
@doc_private
@always_inline
@implicit
fn __init__(out self, none: __mlir_type.`!kgen.none`):
"""Initializes a none value object from a `None` literal.
Expand Down
1 change: 1 addition & 0 deletions stdlib/test/builtin/test_none.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct FromNone:
fn __init__(out self, none: __mlir_type.`!kgen.none`):
self = NoneType()

@implicit
fn __init__(out self, value: Int):
self.value = value

Expand Down

0 comments on commit 43fa507

Please sign in to comment.