-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix complex parameter initialization #3100
Fix complex parameter initialization #3100
Conversation
Updated error message: (lf2) % cat examples/expr2.f90
program expr2
implicit none
integer :: x = 10
complex(8), parameter :: zero = (x, x)
print *, zero
end program
(lf2) % gfortran examples/expr2.f90
examples/expr2.f90:5:39:
5 | complex(8), parameter :: zero = (x, x)
| 1
Error: Expected a right parenthesis in expression at (1)
examples/expr2.f90:6:17:
6 | print *, zero
| 1
Error: Symbol 'zero' at (1) has no IMPLICIT type
(lf2) % lfortran examples/expr2.f90
semantic error: Initialisation of `zero` must reduce to a compile time constant.
--> examples/expr2.f90:5:5
|
5 | complex(8), parameter :: zero = (x, x)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Please report unclear or confusing messages as bugs at
https://github.com/lfortran/lfortran/issues. |
@@ -1944,8 +1944,8 @@ class CommonVisitor : public AST::BaseVisitor<Derived> { | |||
} | |||
ASR::expr_t* init_expr_value = ASRUtils::expr_value(init_expr); | |||
if( init_expr && !ASRUtils::is_value_constant(init_expr_value) ) { | |||
throw SemanticError("Initialisation of " + std::string(x.m_syms[i].m_name) + | |||
" must reduce to a compile time constant.", | |||
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + | |
throw SemanticError("Initialization of `" + std::string(x.m_syms[i].m_name) + |
@@ -2403,8 +2403,8 @@ class CommonVisitor : public AST::BaseVisitor<Derived> { | |||
} else if( ASRUtils::is_value_constant(init_expr) ) { | |||
value = nullptr; | |||
} else { | |||
throw SemanticError("Initialisation of " + std::string(x.m_syms[i].m_name) + | |||
" must reduce to a compile time constant.", | |||
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + | |
throw SemanticError("Initialization of `" + std::string(x.m_syms[i].m_name) + |
@@ -2455,8 +2455,8 @@ class CommonVisitor : public AST::BaseVisitor<Derived> { | |||
*/ | |||
value = ASRUtils::expr_value(init_expr); | |||
if (value == nullptr) { | |||
throw SemanticError("Initialisation of " + std::string(x.m_syms[i].m_name) + | |||
" must reduce to a compile time constant.", | |||
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + | |
throw SemanticError("Initialization of `" + std::string(x.m_syms[i].m_name) + |
@@ -2470,8 +2470,8 @@ class CommonVisitor : public AST::BaseVisitor<Derived> { | |||
type = ASRUtils::TYPE(ASR::make_Character_t(al, int_const->base.base.loc, 1, len, nullptr)); | |||
} | |||
} else { | |||
throw SemanticError("Initialisation of " + std::string(x.m_syms[i].m_name) + | |||
" must reduce to a compile time constant.", | |||
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + | |
throw SemanticError("Initialization of `" + std::string(x.m_syms[i].m_name) + |
@@ -2521,8 +2521,8 @@ class CommonVisitor : public AST::BaseVisitor<Derived> { | |||
value = nullptr; | |||
} | |||
} else { | |||
throw SemanticError("Initialisation of " + std::string(x.m_syms[i].m_name) + | |||
" must reduce to a compile time constant.", | |||
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw SemanticError("Initialisation of `" + std::string(x.m_syms[i].m_name) + | |
throw SemanticError("Initialization of `" + std::string(x.m_syms[i].m_name) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks great, thanks! I left some minor spelling correction.
b1e0f3b
to
e19241b
Compare
Add backquote in err message
e19241b
to
4fe5692
Compare
Also update the error message.
fixes #3098