Skip to content

Commit

Permalink
Fix internal compiler error with certain kinds of INOUT parameters (i…
Browse files Browse the repository at this point in the history
…ssue #146)
  • Loading branch information
ghewgill committed Mar 31, 2017
1 parent 46d3c52 commit 2299a2d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,9 @@ const ast::Expression *Analyzer::analyze(const pt::FunctionCallExpression *expr)
if (not e->type->is_assignment_compatible(ftype->params[p]->type)) {
error2(3194, a->expr->token, "type mismatch", ftype->params[p]->declaration, "function argument here");
}
if (ftype->params[p]->mode == ast::ParameterType::INOUT && not ref->can_generate_address()) {
error(3241, a->expr->token, "using this kind of expression with an INOUT parameter is currently not supported");
}
}
if (ftype->params[p]->mode == ast::ParameterType::OUT && a->mode.type != OUT) {
error(3184, a->expr->token, "OUT keyword required");
Expand Down
5 changes: 5 additions & 0 deletions src/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,7 @@ class ReferenceExpression: public Expression {
ReferenceExpression(const Type *type, bool is_readonly): Expression(type, false, is_readonly) {}

virtual void generate_expr(Emitter &emitter) const override { generate_load(emitter); }
virtual bool can_generate_address() const { return true; }
virtual void generate_address_read(Emitter &) const = 0;
virtual void generate_address_write(Emitter &) const = 0;
virtual void generate_load(Emitter &) const;
Expand All @@ -1646,6 +1647,7 @@ class DummyExpression: public ReferenceExpression {
virtual bool eval_boolean() const override { internal_error("DummyExpression"); }
virtual Number eval_number() const override { internal_error("DummyExpression"); }
virtual std::string eval_string() const override { internal_error("DummyExpression"); }
virtual bool can_generate_address() const { return false; }
virtual void generate_address_read(Emitter &) const override { internal_error("DummyExpression"); }
virtual void generate_address_write(Emitter &) const override { internal_error("DummyExpression"); }
virtual void generate_load(Emitter &) const override { internal_error("DummyExpression"); }
Expand Down Expand Up @@ -1751,6 +1753,7 @@ class StringReferenceIndexExpression: public ReferenceExpression {
virtual bool eval_boolean() const override { internal_error("StringReferenceIndexExpression"); }
virtual Number eval_number() const override { internal_error("StringReferenceIndexExpression"); }
virtual std::string eval_string() const override { internal_error("StringReferenceIndexExpression"); }
virtual bool can_generate_address() const { return false; }
virtual void generate_address_read(Emitter &) const override { internal_error("StringReferenceIndexExpression"); }
virtual void generate_address_write(Emitter &) const override { internal_error("StringReferenceIndexExpression"); }
virtual void generate_load(Emitter &) const override;
Expand Down Expand Up @@ -1803,6 +1806,7 @@ class BytesReferenceIndexExpression: public ReferenceExpression {
virtual bool eval_boolean() const override { internal_error("BytesReferenceIndexExpression"); }
virtual Number eval_number() const override { internal_error("BytesReferenceIndexExpression"); }
virtual std::string eval_string() const override { internal_error("BytesReferenceIndexExpression"); }
virtual bool can_generate_address() const { return false; }
virtual void generate_address_read(Emitter &) const override { internal_error("BytesReferenceIndexExpression"); }
virtual void generate_address_write(Emitter &) const override { internal_error("BytesReferenceIndexExpression"); }
virtual void generate_load(Emitter &) const override;
Expand Down Expand Up @@ -1896,6 +1900,7 @@ class ArrayReferenceRangeExpression: public ReferenceExpression {
virtual bool eval_boolean() const override { internal_error("ArrayReferenceRangeExpression"); }
virtual Number eval_number() const override { internal_error("ArrayReferenceRangeExpression"); }
virtual std::string eval_string() const override { internal_error("ArrayReferenceRangeExpression"); }
virtual bool can_generate_address() const { return false; }
virtual void generate_address_read(Emitter &) const override { internal_error("StringReferenceRangeExpression"); }
virtual void generate_address_write(Emitter &) const override { internal_error("StringReferenceRangeExpression"); }
virtual void generate_load(Emitter &) const override;
Expand Down
6 changes: 6 additions & 0 deletions t/errors/N3241.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FUNCTION a_inout(INOUT p: Array<Number>)
END FUNCTION

VAR a: Array<Number> := []
a_inout(INOUT a[0 TO 4])
%<
2 changes: 1 addition & 1 deletion t/parameter-inout-array.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% TODO
% TODO https://github.com/ghewgill/neon-lang/issues/146
FUNCTION a_inout(INOUT p: Array<Number>)
p := [1, 2]
END FUNCTION
Expand Down

0 comments on commit 2299a2d

Please sign in to comment.