This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug translator/16097] improve error message on array type mismatch


https://sourceware.org/bugzilla/show_bug.cgi?id=16097

--- Comment #7 from Jonathan Lebon <jlebon at redhat dot com> ---
After looking more into the limitations of the current method of reporting
mismatches, I decided to change things up a bit. Each time we resolve a
variable or function (including array indexes and function arguments), we
remember
   1. the token that led us to make the resolution,
   2. the type to which we resolved,
   3. the index of the symbol we resolved (if it's an array index or function
argument), and
   4. the symdecl of the associated variable/function.

I've additionally implemented a sort of filter to only print out the most
relevant of error messages so that the terminal is not cluttered with
'by-product' mismatches.

I have created a new branch jlebon/mismatch. The branch also contains test
cases in scripts/mismatches. Here are a few examples of before and after:

1. SIMPLE 'EXPECTED BUT FOUND'

$ cat comparison.stp
probe begin {
    if (42 > "life")
        next
}

$ stap comparison.stp ### BEFORE
semantic error: type mismatch (long vs. string): number '42' at
comparison.stp:2:6
        source:     if (42 > "life")
                        ^

semantic error: type mismatch (long vs. string): operator '>' at :2:9
        source:     if (42 > "life")
                           ^

semantic error: type was first inferred here (string): operator '>' at :2:9
        source:     if (42 > "life")
                           ^

Pass 2: analysis failed.  [man error::pass2]
Number of similar error messages suppressed: 1.
Rerun with -v to see them.

$ stap comparison.stp ### NOW
semantic error: type mismatch: expected string but found long: number '42' at
comparison.stp:2:6
        source:     if (42 > "life")
                        ^

Pass 2: analysis failed.  [man error::pass2]
Number of similar error messages suppressed: 1.
Rerun with -v to see them.

2. ARRAY INDEXES

$ cat arrayindex.2.stp
global y
probe begin {
   y[1, "str", 5] = "string1"
   y[3, "ing", 7] = "string2"
   y[8, "bla", "bli"] = "string3"
   print(y[2,"bla",1])
}

$ stap arrayindex.2.stp ### BEFORE
semantic error: type mismatch (string vs. long): string 'bli' at
arrayindex.2.stp:5:16
        source:    y[8, "bla", "bli"] = "string3"
                               ^

semantic error: type mismatch (string vs. long): identifier 'y' at :5:4
        source:    y[8, "bla", "bli"] = "string3"
                   ^

semantic error: type was first inferred here (long): identifier 'y' at :3:4
        source:    y[1, "str", 5] = "string1"
                   ^

Pass 2: analysis failed.  [man error::pass2]

$ stap arrayindex.2.stp ### NOW
semantic error: index 2 type mismatch (string): string 'bli' at
arrayindex.2.stp:5:16
        source:    y[8, "bla", "bli"] = "string3"
                               ^

semantic error: type of index 2  was first inferred here (long): number '5' at
:3:16
        source:    y[1, "str", 5] = "string1"
                               ^

Pass 2: analysis failed.  [man error::pass2]

3. FUNCTION ARGS

$ cat functioncall.2.stp
function func(x,y) {
   x .= "str"
   y += 1
   print(x)
   print(y)
}
probe begin {
   func("str", "ing")
}

$ stap functioncall.2.stp ### BEFORE
semantic error: type mismatch (long vs. string): identifier 'y' at
functioncall.2.stp:3:4
        source:    y += 1
                   ^

semantic error: type was first inferred here (string): identifier 'y' at :3:4
        source:    y += 1
                   ^

Pass 2: analysis failed.  [man error::pass2]

$ stap functioncall.2.stp ### NOW
semantic error: index 1 type mismatch (long): identifier 'y' at
functioncall.2.stp:3:4
        source:    y += 1
                   ^

semantic error: type of index 1  was first inferred here (string): string 'ing'
at :8:16
        source:    func("str", "ing")
                               ^

Pass 2: analysis failed.  [man error::pass2]

4. FUNCTION RETURN TYPE

$ cat return_statement.stp
function func(x) {
    if (x)
        return 1
    else
        return "string"
}
probe begin {
    print(func(0))
}

$ stap return_statement.stp ### BEFORE
semantic error: type mismatch (string vs. long): string 'string' at
return_statement.stp:5:10
        source:         return "string"
                               ^

semantic error: type mismatch (long vs. string): identifier 'func' at :1:10
        source: function func(x) {
                         ^

semantic error: type was first inferred here (string): identifier 'func' at
:1:10
        source: function func(x) {
                         ^

Pass 2: analysis failed.  [man error::pass2]

$ stap return_statement.stp ### NOW
semantic error: type mismatch (string): string 'string' at
return_statement.stp:5:10
        source:         return "string"
                               ^

semantic error: type was first inferred here (long): number '1' at :3:10
        source:         return 1
                               ^

Pass 2: analysis failed.  [man error::pass2]

5. REFERENT-T (SAME TYPE OF MISMATCH AS THE SCRIPT IN DESCRIPTION OF THIS PR)

$ cat referent-t.stp
global x
probe begin {
    x = 1
    x = sprintf("string")
}

$ stap referent-t.stp ### BEFORE
semantic error: type mismatch (long vs. string): identifier 'x' at
referent-t.stp:1:8
        source: global x
                       ^

semantic error: type was first inferred here (string): identifier 'x' at :3:2
        source:     x = 1
                    ^

Pass 2: analysis failed.  [man error::pass2]

$ stap referent-t.stp ### NOW
semantic error: type mismatch (string): identifier 'x' at referent-t.stp:4:2
        source:     x = sprintf("string")
                    ^

semantic error: type was first inferred here (long): identifier 'x' at :3:2
        source:     x = 1
                    ^

Pass 2: analysis failed.  [man error::pass2]

-- 
You are receiving this mail because:
You are the assignee for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]