Skip to content

Commit

Permalink
Merge branch 'master' into vaivaswatha/issue6321
Browse files Browse the repository at this point in the history
  • Loading branch information
vaivaswatha authored Aug 7, 2024
2 parents b21a20e + cd0213a commit c3713a8
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ty::TyIntrinsicFunctionKind {
type_check_contract_ret(handler, ctx, kind, arguments, type_arguments, span)
}
Intrinsic::EncodeBufferEmpty => {
type_check_encode_buffer_empty(ctx, kind, arguments, type_arguments, span)
type_check_encode_buffer_empty(handler, ctx, kind, arguments, type_arguments, span)
}
Intrinsic::EncodeBufferAppend => {
type_check_encode_append(handler, ctx, kind, arguments, type_arguments, span)
Expand Down Expand Up @@ -417,13 +417,20 @@ fn new_encoding_buffer_tuple(
}

fn type_check_encode_buffer_empty(
handler: &Handler,
ctx: TypeCheckContext,
kind: sway_ast::Intrinsic,
arguments: &[Expression],
_type_arguments: &[TypeArgument],
span: Span,
) -> Result<(ty::TyIntrinsicFunctionKind, TypeId), ErrorEmitted> {
assert!(arguments.is_empty());
if !arguments.is_empty() {
return Err(handler.emit_err(CompileError::IntrinsicIncorrectNumArgs {
name: kind.to_string(),
expected: 0,
span,
}));
}

let type_engine = ctx.engines.te();
let engines = ctx.engines();
Expand Down Expand Up @@ -485,6 +492,14 @@ fn type_check_encode_append(
_type_arguments: &[TypeArgument],
span: Span,
) -> Result<(ty::TyIntrinsicFunctionKind, TypeId), ErrorEmitted> {
if arguments.len() != 2 {
return Err(handler.emit_err(CompileError::IntrinsicIncorrectNumArgs {
name: kind.to_string(),
expected: 2,
span,
}));
}

let type_engine = ctx.engines.te();
let engines = ctx.engines();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "encode_append_wrong_args"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "encode_append_wrong_args"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
library;

pub struct Buffer {
buffer: u64
}

pub trait T {
fn ar(buffer: Buffer) -> Buffer;
}

impl T for str[10] {
fn ar(buffer: Buffer) -> Buffer {
Buffer {
buffer: __encode_buffer_append(buffer.buffer)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
category = "fail"

# check: $()warning
# check: $()buffer: __encode_buffer_append(buffer.buffer)

# check: $()buffer: __encode_buffer_append(buffer.buffer)
# nextln: $()Call to "encode_buffer_append" expects 2 arguments
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = "core"
source = "path+from-root-BABDDF1B461AF6DA"

[[package]]
name = "encode_buffer_empty_with_args"
source = "member"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "encode_buffer_empty_with_args"
entry = "main.sw"

[dependencies]
core = { path = "../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library;

struct Buffer {
buffer: (raw_ptr, u64, u64),
}

impl Buffer {
pub fn new() -> Self {
Buffer {
buffer: __encode_buffer_empty(self),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "fail"

# check: $()buffer: __encode_buffer_empty(self),
# nextln: $()Call to "encode_buffer_empty" expects 0 arguments

0 comments on commit c3713a8

Please sign in to comment.