diff --git a/src/main/java/org/yinwang/pysonar/visitor/TypeInferencer.java b/src/main/java/org/yinwang/pysonar/visitor/TypeInferencer.java index 10ff5f1d..b94712fc 100644 --- a/src/main/java/org/yinwang/pysonar/visitor/TypeInferencer.java +++ b/src/main/java/org/yinwang/pysonar/visitor/TypeInferencer.java @@ -213,8 +213,11 @@ public Type visit(Call node, State s) { { Node target = ((Attribute) node.func).target; Name attr = ((Attribute) node.func).attr; - selfType = visit(target, s); - Set b = selfType.table.lookupAttr(attr.id); + Type targetType = visit(target, s); + if (!(targetType instanceof ModuleType)) { + selfType = targetType; + } + Set b = targetType.table.lookupAttr(attr.id); if (b != null) { Analyzer.self.putRef(attr, b); fun = State.makeUnion(b); diff --git a/tests/import/same-level.test/mod1.py b/tests/import/same-level.test/mod1.py index 37fde871..7ab255cd 100644 --- a/tests/import/same-level.test/mod1.py +++ b/tests/import/same-level.test/mod1.py @@ -2,3 +2,6 @@ o = mod2.B() print o.a + +u = mod2.foo(10) +print u diff --git a/tests/import/same-level.test/mod2.py b/tests/import/same-level.test/mod2.py index 57ac51d6..24a89980 100644 --- a/tests/import/same-level.test/mod2.py +++ b/tests/import/same-level.test/mod2.py @@ -1,2 +1,6 @@ class B: - a = 'hi' + a = 'hi' + + +def foo(x): + return x + 1 diff --git a/tests/import/same-level.test/refs.json b/tests/import/same-level.test/refs.json index 80e91dd9..b6e26396 100644 --- a/tests/import/same-level.test/refs.json +++ b/tests/import/same-level.test/refs.json @@ -96,12 +96,96 @@ { "name": "a", "file": "mod2.py", - "start": 11, - "end": 12, + "start": 13, + "end": 14, "line": 2, - "col": 3, + "col": 5, "type": "str" } ] + }, + { + "ref": { + "name": "mod2", + "file": "mod1.py", + "start": 41, + "end": 45, + "line": 6, + "col": 5 + }, + "dests": [ + { + "name": "mod2", + "file": "mod2.py", + "start": 0, + "end": 0, + "line": 0, + "col": 0, + "type": "mod2" + } + ] + }, + { + "ref": { + "name": "foo", + "file": "mod1.py", + "start": 46, + "end": 49, + "line": 6, + "col": 10 + }, + "dests": [ + { + "name": "foo", + "file": "mod2.py", + "start": 28, + "end": 31, + "line": 5, + "col": 5, + "type": "int -> int" + } + ] + }, + { + "ref": { + "name": "x", + "file": "mod2.py", + "start": 47, + "end": 48, + "line": 6, + "col": 12 + }, + "dests": [ + { + "name": "x", + "file": "mod2.py", + "start": 32, + "end": 33, + "line": 5, + "col": 9, + "type": "int" + } + ] + }, + { + "ref": { + "name": "u", + "file": "mod1.py", + "start": 60, + "end": 61, + "line": 7, + "col": 7 + }, + "dests": [ + { + "name": "u", + "file": "mod1.py", + "start": 37, + "end": 38, + "line": 6, + "col": 1, + "type": "int" + } + ] } ] \ No newline at end of file