Opened 12 years ago
Closed 12 years ago
#1833 closed defect (fixed)
Local name shadowing and assignment to inputs
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | high | Milestone: | 1.9.0 |
Component: | Frontend | Version: | trunk |
Keywords: | Cc: |
Description
When calling this test function no warning is given that x
and y
don't have the correct types. Are the input variables used in the match instead? The program exits silently.
package P function test input Integer x; input String y; algorithm _ := match (x,y) local String x; Integer y; case (x,y) then (); end match; end test; end P;
Change History (8)
comment:1 by , 12 years ago
Component: | Backend → Frontend |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 12 years ago
How to detect these things:
Index: Compiler/FrontEnd/Static.mo =================================================================== --- Compiler/FrontEnd/Static.mo (revision 13057) +++ Compiler/FrontEnd/Static.mo (working copy) @@ -327,7 +327,7 @@ Error.addSourceMessage(Error.ASSIGN_READONLY_ERROR, {"input", cr_str}, inInfo); then - fail(); + (); else (); Index: Compiler/FrontEnd/Patternm.mo =================================================================== --- Compiler/FrontEnd/Patternm.mo (revision 13056) +++ Compiler/FrontEnd/Patternm.mo (working copy) @@ -162,7 +162,7 @@ output Env.Cache outCache; output DAE.Pattern pattern; algorithm - (outCache,pattern) := elabPattern2(cache,env,lhs,ty,info,Error.getNumErrorMessages(),allowTopLevelInputs); + (outCache,pattern) := elabPattern2(cache,env,lhs,ty,info,Error.getNumErrorMessages(),false); end elabPattern; protected function elabPattern2
omc MainTest.mos | grep input | sort > log && wc -l log
comment:4 by , 12 years ago
The following script removed 98% of all occurrences of matching to an input variable:
#!/bin/bash while read line; do FILE=`echo $line | cut -d: -f1 | cut "-d[" -f2` LINE1=`echo $line | cut -d: -f2 | cut -d: -f3` LINE2=`echo $line | cut -d: -f3 | cut -d: -f4 | cut -d- -f2` PAT=`echo $line | cut "-d " -f9` for LINE in `seq $LINE1 $LINE2`; do echo "Processing $FILE $LINE using $PAT" if sed -n "$LINE"p "$FILE" | egrep -q "equation|then|else"; then sed -i "$LINE""s/case $PAT/case _/g" "$FILE" sed -i "$LINE""s/case *($PAT)/case _/g" "$FILE" sed -i "$LINE""s/case *($PAT,/case (_,/g" "$FILE" sed -i "$LINE""s/ *$PAT *then/ _ then/g" "$FILE" sed -i "$LINE""s/ *, *$PAT) *then/,_) then/g" "$FILE" sed -i "$LINE""s/ *$PAT *equation/ _ equation/g" "$FILE" sed -i "$LINE""s/ *, *$PAT) *equation/,_) equation/g" "$FILE" sed -i "$LINE""s/_ *, *$PAT as */_,/g" "$FILE" sed -i "$LINE""s/_ *, *$PAT/_,_/g" "$FILE" sed -i "$LINE""s/ *$PAT *, *_/_,_/g" "$FILE" sed -i "$LINE""s/,$PAT,_/,_,_/g" "$FILE" sed -i "$LINE""s/,$PAT, _/,_,_/g" "$FILE" sed -i "$LINE""s/_,$PAT,/_,_,/g" "$FILE" sed -i "$LINE""s/$PAT as //g" "$FILE" else sed -i "$LINE""s/,$PAT,/,_,/g" "$FILE" sed -i "$LINE""s/, *$PAT *,/, _,/g" "$FILE" sed -i "$LINE""s/($PAT,/(_,/g" "$FILE" sed -i "$LINE""s/( $PAT,/(_,/g" "$FILE" sed -i "$LINE""s/,$PAT)/,_)/g" "$FILE" sed -i "$LINE""s/, *$PAT)/, _)/g" "$FILE" sed -i "$LINE""s/ $PAT)/ _)/g" "$FILE" sed -i "$LINE""s/ $PAT,/ _,/g" "$FILE" sed -i "$LINE""s/ ${PAT}\$/ _/g" "$FILE" sed -i "$LINE""s/case($PAT)/case _/g" "$FILE" sed -i "$LINE""s/($PAT)/_/g" "$FILE" sed -i "$LINE""s/$PAT *as //g" "$FILE" fi done done < log
comment:5 by , 12 years ago
This will be the testcase for the original bug-report (it tests what was actually wrong in a better way):
model CheckInputScope package P function test input Integer x; algorithm _ := match (x,y) local Integer y; case (x,y) then (); end match; end test; end P; algorithm P.test(1); end CheckInputScope;
comment:7 by , 12 years ago
The reason the duplicates weren't detected was that the check came after unused local declarations were removed
comment:8 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Summary: | Warning for local name shadowing isn't always triggered → Local name shadowing and assignment to inputs |
Fixed in r13062
Note:
See TracTickets
for help on using tickets.
If noone objects in the next
x
minutes (wherex
is the time it will take me to fix this), I will remove the possibility to match against input arguments (assignment to input is not valid Modelica) and consider also making name shadowing an error in MetaModelica (duplicate elements are disallowed in Modelica anyway).