Changeset 6918


Ignore:
Timestamp:
2010-11-09T09:15:14+01:00 (14 years ago)
Author:
sjoelund.se
Message:

Fix for bug #1350

  • Check for invalid named fields in pattern record deconstructor
Location:
branches/sjoelund-functiontree
Files:
2 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/sjoelund-functiontree

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/sjoelund-functiontree/Compiler/Error.mo

    r6542 r6918  
    283283public constant ErrorID META_STRICT_RML_MATCH_IN_OUT=5016;
    284284public constant ErrorID META_NONE_CREF=5017;
     285public constant ErrorID META_INVALID_PATTERN_NAMED_FIELD=5018;
    285286
    286287protected constant list<tuple<Integer, MessageType, Severity, String>> errorTable=
     
    638639          (LOOKUP_FUNCTION_GOT_CLASS,TRANSLATION(),ERROR(),"Looking for a function %s but found a %s."),
    639640          (META_STRICT_RML_MATCH_IN_OUT,TRANSLATION(),ERROR(),"%s. Strict RML enforces match expression input and output to be the same as the function's."),
    640           (META_NONE_CREF,TRANSLATION(),ERROR(),"NONE is not acceptable syntax. Use NONE() instead.")
     641          (META_NONE_CREF,TRANSLATION(),ERROR(),"NONE is not acceptable syntax. Use NONE() instead."),
     642          (META_INVALID_PATTERN_NAMED_FIELD,TRANSLATION(),ERROR(),"Invalid named fields: %s")
    641643          };
    642644
  • branches/sjoelund-functiontree/Compiler/Patternm.mo

    r6760 r6918  
    486486      RenamedPat pat,first2,second2;
    487487      Integer constTag,i,numPosArgs;
    488       list<Absyn.NamedArg> namedArgList;
     488      list<Absyn.NamedArg> namedArgList,invalidArgs;
    489489      Absyn.Path recName,pathName;
    490490      SCode.Class sClass;
     
    611611
    612612        // CALL EXPRESSION - translates pos/named args into only pos ones
    613     case (Absyn.CALL(compRef,Absyn.FUNCTIONARGS(funcArgs,namedArgList)),
    614         localVar,localAsBinds,localCache,localEnv,localConstTagEnv,info)
     613    case (Absyn.CALL(compRef,Absyn.FUNCTIONARGS(funcArgs,namedArgList)),localVar,localAsBinds,localCache,localEnv,localConstTagEnv,info)
    615614      equation
    616615        recName = Absyn.crefToPath(compRef);
     
    628627
    629628        //Sorting of named arguments
    630         funcArgsNamedFixed = generatePositionalArgs(fieldNamesNamed,namedArgList,{});
     629        (funcArgsNamedFixed,invalidArgs) = generatePositionalArgs(fieldNamesNamed,namedArgList,{});
    631630        funcArgs = listAppend(funcArgs,funcArgsNamedFixed);
    632631
    633         (localCache,renamedPatList,localAsBinds2,localConstTagEnv,status) = renamePatList(funcArgs
    634           ,localVar2,1,{},{},localCache,localEnv,localConstTagEnv,info);
     632        (localCache,renamedPatList,localAsBinds2,localConstTagEnv,status) = renamePatList(funcArgs,localVar2,1,{},{},localCache,localEnv,localConstTagEnv,info);
    635633        pat = DFA.RP_CALL(localVar,compRef,renamedPatList);
    636 
     634        status = checkInvalidPatternNamedArgs(invalidArgs,status,info);
    637635      then (localCache,pat,listAppend(localAsBinds,localAsBinds2),localConstTagEnv,status);
    638636        // EMPTY LIST EXPRESSION
     
    20011999  input list<Absyn.Exp> accList;
    20022000  output list<Absyn.Exp> outList;
    2003 algorithm
    2004   outList :=
    2005   matchcontinue (fieldNameList,namedArgList,accList)
     2001  output list<Absyn.NamedArg> outInvalidNames;
     2002algorithm
     2003  (outList,outInvalidNames) := matchcontinue (fieldNameList,namedArgList,accList)
    20062004    local
    20072005      list<Absyn.Exp> localAccList;
    20082006      list<Absyn.Ident> restFieldNames;
    20092007      Absyn.Ident firstFieldName;
    2010       list<Absyn.Exp> expL;
     2008      Absyn.Exp exp;
    20112009      list<Absyn.NamedArg> localNamedArgList;
    2012     case ({},_,localAccList) then localAccList;
     2010    case ({},namedArgList,localAccList) then (listReverse(localAccList),namedArgList);
    20132011    case (firstFieldName :: restFieldNames,localNamedArgList,localAccList)
    20142012      equation
    2015         expL = Util.listCreate(findFieldExpInList(firstFieldName,localNamedArgList));
    2016         localAccList = listAppend(localAccList,expL);
    2017         localAccList = generatePositionalArgs(restFieldNames,localNamedArgList,localAccList);
    2018       then localAccList;
     2013        (exp,localNamedArgList) = findFieldExpInList(firstFieldName,localNamedArgList);
     2014        (localAccList,localNamedArgList) = generatePositionalArgs(restFieldNames,localNamedArgList,exp::localAccList);
     2015      then (localAccList,localNamedArgList);
    20192016  end matchcontinue;
    20202017end generatePositionalArgs;
     
    20272024  input list<Absyn.NamedArg> namedArgList;
    20282025  output Absyn.Exp outExp;
    2029 algorithm
    2030   outExp :=
    2031   matchcontinue (firstFieldName,namedArgList)
     2026  output list<Absyn.NamedArg> outNamedArgList;
     2027algorithm
     2028  (outExp,outNamedArgList) := matchcontinue (firstFieldName,namedArgList)
    20322029    local
    20332030      Absyn.Exp e;
    20342031      Absyn.Ident localFieldName,aName;
    2035       list<Absyn.NamedArg> restNamedArgList;
    2036     case (_,{}) then Absyn.CREF(Absyn.WILD());
    2037     case (localFieldName,Absyn.NAMEDARG(aName,e) :: _)
     2032      list<Absyn.NamedArg> rest;
     2033      Absyn.NamedArg first;
     2034    case (_,{}) then (Absyn.CREF(Absyn.WILD()),{});
     2035    case (localFieldName,Absyn.NAMEDARG(aName,e) :: rest)
    20382036      equation
    20392037        true = stringEq(localFieldName,aName);
    2040       then e;
    2041     case (localFieldName,_ :: restNamedArgList)
    2042       equation
    2043         e = findFieldExpInList(localFieldName,restNamedArgList);
    2044       then e;
     2038      then (e,rest);
     2039    case (localFieldName,first::rest)
     2040      equation
     2041        (e,rest) = findFieldExpInList(localFieldName,rest);
     2042      then (e,first::rest);
    20452043  end matchcontinue;
    20462044end findFieldExpInList;
     
    26312629end getCaseDecls;
    26322630
     2631protected function checkInvalidPatternNamedArgs
     2632"Checks that there are no invalid named arguments in the pattern"
     2633  input list<Absyn.NamedArg> args;
     2634  input Util.Status status;
     2635  input Absyn.Info info;
     2636  output Util.Status outStatus;
     2637algorithm
     2638  outStatus := match (args,status,info)
     2639    local
     2640      list<String> argsNames;
     2641      String str1;
     2642    case ({},status,_) then status;
     2643    case (args,status,info)
     2644      equation
     2645        (argsNames,_) = Absyn.getNamedFuncArgNamesAndValues(args);
     2646        str1 = Util.stringDelimitList(argsNames, ",");
     2647        Error.addSourceMessage(Error.META_INVALID_PATTERN_NAMED_FIELD, {str1}, info);
     2648      then Util.FAILURE();
     2649  end match;
     2650end checkInvalidPatternNamedArgs;
     2651
    26332652end Patternm;
  • branches/sjoelund-functiontree/testsuite/meta/ErrorInvalidPattern1.mo

    r6917 r6918  
    1 // name: ErrorInvalidPattern
     1// name: ErrorInvalidPattern1
    22// cflags: +g=MetaModelica
    33// status: incorrect
    4 package ErrorInvalidPattern
     4
     5package ErrorInvalidPattern1
    56
    67function fn
     
    1516constant String str = fn("");
    1617
    17 end ErrorInvalidPattern;
     18end ErrorInvalidPattern1;
     19
    1820// Result:
    19 // Error processing file: ErrorInvalidPattern.mo
    20 // [ErrorInvalidPattern.mo:11:10-11:19:writable] Error: Invalid pattern: str + ""
     21// Error processing file: ErrorInvalidPattern1.mo
     22// [ErrorInvalidPattern1.mo:12:10-12:19:writable] Error: Invalid pattern: str + ""
    2123//
    2224// # Error encountered! Exiting...
  • branches/sjoelund-functiontree/testsuite/meta/Makefile

    r6532 r6918  
    1616EqPatternm.mos \
    1717ErrorInteractiveCallFunctionPtr.mos \
    18 ErrorInvalidPattern.mo \
     18ErrorInvalidPattern1.mo \
     19ErrorInvalidPattern2.mo \
     20ErrorInvalidPattern3.mo \
    1921ErrorMatchInOut1.mo \
    2022ErrorMatchInOut2.mo \
Note: See TracChangeset for help on using the changeset viewer.