Menu

#221 Integers in patterns

None
closed
None
6
2017-02-15
2017-02-14
No

Pattern match of an integer against a string crashes: numerics need automatic conversion to the string type.

1 Attachments

Discussion

  • Bruce Rennie

    Bruce Rennie - 2017-02-15

    At first look, the problem seems to be related to the RTL macro cnv_pattern_macro which only has valid type-cases for string, cset and pattern. Other convertable values do not appear to be handled at this point.

     
  • Bruce Rennie

    Bruce Rennie - 2017-02-15

    I have submitted a possible interim fix for review - this makes changes to the unicon compiler and not to the RTL runtime code.

     
  • Clinton Jeffery

    Clinton Jeffery - 2017-02-15
    • status: open --> pending-fixed
    • assigned_to: Clinton Jeffery
    • Group: -->
     
  • Clinton Jeffery

    Clinton Jeffery - 2017-02-15

    Committed a fix consisting of: anything that's not a pattern or a cset now attempts to convert to string and becomes a string pattern if that succeeds (class Icon conversion semantics).

     
  • Bruce Rennie

    Bruce Rennie - 2017-02-15

    Have tested the fix with the following program

    procedure main()
    s1 := "0123456"
    s2 := "0123456"
    s3 := "0123.456"

     t := table()
     t["3"] := "3"
     t[3] := 3
     t[3.4] := 3.4
    
     l := ["3", 3, 3.4]
    
    
     s1 ?? "3" := "X"
     write("s1 string match: ", s1)
    
     s2 ?? 3 := "Y"
     write("s2 string match: ", s2)
    
     s3 ?? 3.4 := "Z"
     write("s3 string match: ", s3)
    
     every t1 := !t do {
        s3 := "0123.456"
        s3 ?? t1 := "A"
        write("s3 string match: ", s3)
     }
    
     every i := 1 to 3 do {
        s3 := "0123.456"
        s3 ?? l[i] := "B"
        write("s3 string match: ", s3)
     }
    

    end

    The output from this program is

    s1 string match: 012X456
    s2 string match: 012Y456
    s3 string match: 012Z56
    s3 string match: 012A.456
    s3 string match: 012A.456
    s3 string match: 012A56
    s3 string match: 012B.456
    s3 string match: 012B.456
    s3 string match: 012B56

    The output appears correct. I suggest that this problem can now be closed

     
  • Clinton Jeffery

    Clinton Jeffery - 2017-02-15
    • status: pending-fixed --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB