Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit d98c067

Browse files
perostOpenModelica-Hudson
authored andcommitted
Notify about constant values in match inputs.
Belonging to [master]: - #2277 - OpenModelica/OpenModelica-testsuite#876
1 parent f2d4242 commit d98c067

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

3rdParty

Submodule 3rdParty updated 166 files

Compiler/FrontEnd/Expression.mo

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7931,13 +7931,15 @@ algorithm
79317931
list<DAE.Exp> ae;
79327932
list<list<DAE.Exp>> matrix;
79337933

7934-
case (DAE.ICONST()) then true;
7935-
case (DAE.RCONST()) then true;
7936-
case (DAE.BCONST()) then true;
7937-
case (DAE.SCONST()) then true;
7938-
case (DAE.ENUM_LITERAL()) then true;
7939-
case (DAE.ARRAY(array = ae)) then isConstValueWorkList(ae);
7940-
case (DAE.MATRIX(matrix = matrix)) then isConstValueWorkListList(matrix);
7934+
case DAE.ICONST() then true;
7935+
case DAE.RCONST() then true;
7936+
case DAE.BCONST() then true;
7937+
case DAE.SCONST() then true;
7938+
case DAE.ENUM_LITERAL() then true;
7939+
case DAE.ARRAY(array = ae) then isConstValueWorkList(ae);
7940+
case DAE.MATRIX(matrix = matrix) then isConstValueWorkListList(matrix);
7941+
case DAE.RECORD() then true;
7942+
case DAE.METARECORDCALL() then true;
79417943
else false;
79427944

79437945
end match;

Compiler/FrontEnd/Patternm.mo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ algorithm
782782
(matchDecls,ht) = filterUnusedDecls(matchDecls,ht,{},HashTableStringToPath.emptyHashTableSized(hashSize));
783783
(elabExps,inputAliases,elabCases) = filterUnusedPatterns(elabExps,inputAliases,elabCases) "filterUnusedPatterns() again to filter out the last parts.";
784784
(elabMatchTy, elabCases) = optimizeMatchToSwitch(matchTy,elabCases,info);
785+
checkConstantMatchInputs(elabExps, info);
785786
exp = DAE.MATCHEXPRESSION(elabMatchTy,elabExps,inputAliases,matchDecls,elabCases,et);
786787
then (cache,exp,prop);
787788
else
@@ -793,6 +794,17 @@ algorithm
793794
end matchcontinue;
794795
end elabMatchExpression;
795796

797+
protected function checkConstantMatchInputs
798+
input list<DAE.Exp> inputs;
799+
input SourceInfo info;
800+
algorithm
801+
for i in inputs loop
802+
if Expression.isConstValue(i) then
803+
Error.addSourceMessage(Error.META_MATCH_CONSTANT, {ExpressionDump.printExpStr(i)}, info);
804+
end if;
805+
end for;
806+
end checkConstantMatchInputs;
807+
796808
protected function optimizeMatchToSwitch
797809
"match str case 'str1' ... case 'str2' case 'str3' => switch hash(str)...
798810
match ut case UT1 ... case UT2 ... case UT3 => switch valueConstructor(ut)...

Compiler/Util/Error.mo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,9 @@ public constant Message UNIONTYPE_WRONG_NUM_TYPEVARS = MESSAGE(5045, TRANSLATION
10441044
Util.gettext("Uniontype %s has %s type variables, but got %s."));
10451045
public constant Message SERIALIZED_SIZE = MESSAGE(5046, TRANSLATION(), NOTIFICATION(),
10461046
Util.gettext("%s uses %s of memory (%s without GC overhead; %s is consumed by not performing String sharing)."));
1047+
public constant Message META_MATCH_CONSTANT = MESSAGE(5047, TRANSLATION(), NOTIFICATION(),
1048+
Util.gettext("Match input %s is a constant value."));
1049+
10471050

10481051
public constant Message COMPILER_ERROR = MESSAGE(5999, TRANSLATION(), ERROR(),
10491052
Util.notrans("%s"));

0 commit comments

Comments
 (0)