diff options
author | Araq <rumpf_a@web.de> | 2011-01-06 09:06:43 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-01-06 09:06:43 +0100 |
commit | 27bc9296d1dae1a0c1939a3b3219c42c83ac638e (patch) | |
tree | 9feed989b8a891be8bd5f3c8deb45db486bae361 | |
parent | da325bc7a4590e7f7f388a0df941a10030bf445b (diff) | |
download | Nim-27bc9296d1dae1a0c1939a3b3219c42c83ac638e.tar.gz |
bugfix: compiler rejects methods without object parameter
-rwxr-xr-x | rod/cgmeth.nim | 3 | ||||
-rwxr-xr-x | rod/msgs.nim | 2 | ||||
-rwxr-xr-x | rod/semstmts.nim | 14 | ||||
-rwxr-xr-x | rod/types.nim | 2 | ||||
-rwxr-xr-x | tests/reject/spec.csv | 2 | ||||
-rw-r--r-- | tests/reject/tmethod.nim | 4 | ||||
-rwxr-xr-x | todo.txt | 4 |
7 files changed, 28 insertions, 3 deletions
diff --git a/rod/cgmeth.nim b/rod/cgmeth.nim index 7b3e5a75f..fe1b581f9 100755 --- a/rod/cgmeth.nim +++ b/rod/cgmeth.nim @@ -17,9 +17,6 @@ proc methodCall*(n: PNode): PNode proc generateMethodDispatchers*(): PNode # implementation -const - skipPtrs = {tyVar, tyPtr, tyRef, tyGenericInst} - proc genConv(n: PNode, d: PType, downcast: bool): PNode = var dest, source: PType diff --git a/rod/msgs.nim b/rod/msgs.nim index bae60df97..d6fde38b4 100755 --- a/rod/msgs.nim +++ b/rod/msgs.nim @@ -107,6 +107,7 @@ type errArrayExpectsTwoTypeParams, errInvalidVisibilityX, errInitHereNotAllowed, errXCannotBeAssignedTo, errIteratorNotAllowed, errXNeedsReturnType, errInvalidCommandX, errXOnlyAtModuleScope, + errXNeedsParamObjectType, errTemplateInstantiationTooNested, errInstantiationFrom, errInvalidIndexValueForTuple, errCommandExpectsFilename, errXExpected, errInvalidSectionStart, errGridTableNotImplemented, errGeneralParseError, @@ -233,6 +234,7 @@ const "iterators can only be defined at the module\'s top level", "$1 needs a return type", "invalid command: \'$1\'", "\'$1\' is only allowed at top level", + "'$1' needs a parameter that has an object type", "template/macro instantiation too nested", "instantiation from here", "invalid index value for tuple subscript", "command expects a filename argument", "\'$1\' expected", diff --git a/rod/semstmts.nim b/rod/semstmts.nim index b449c995a..95974e7be 100755 --- a/rod/semstmts.nim +++ b/rod/semstmts.nim @@ -754,6 +754,20 @@ proc semProc(c: PContext, n: PNode): PNode = proc semMethod(c: PContext, n: PNode): PNode = if not isTopLevel(c): liMessage(n.info, errXOnlyAtModuleScope, "method") result = semProcAux(c, n, skMethod, methodPragmas) + + var s = result.sons[namePos].sym + var t = s.typ + var hasObjParam = false + + for col in countup(1, sonsLen(t)-1): + if skipTypes(t.sons[col], skipPtrs).kind == tyObject: + hasObjParam = true + break + + # XXX this not really correct way to do it: Perhaps it should be done after + # generic instantiation. Well it's good enough for now: + if not hasObjParam: + liMessage(n.info, errXNeedsParamObjectType, "method") proc semConverterDef(c: PContext, n: PNode): PNode = if not isTopLevel(c): liMessage(n.info, errXOnlyAtModuleScope, "converter") diff --git a/rod/types.nim b/rod/types.nim index 32f9c7a94..d7b956983 100755 --- a/rod/types.nim +++ b/rod/types.nim @@ -56,6 +56,8 @@ const abstractVarRange* = {tyGenericInst, tyRange, tyVar, tyDistinct, tyOrdinal} abstractInst* = {tyGenericInst, tyDistinct, tyOrdinal} + skipPtrs* = {tyVar, tyPtr, tyRef, tyGenericInst} + proc skipTypes*(t: PType, kinds: TTypeKinds): PType proc elemType*(t: PType): PType proc containsObject*(t: PType): bool diff --git a/tests/reject/spec.csv b/tests/reject/spec.csv index 8f82529b3..6b1165677 100755 --- a/tests/reject/spec.csv +++ b/tests/reject/spec.csv @@ -14,6 +14,7 @@ tinout.nim;7;for a 'var' type a variable needs to be passed tinvalidnewseq.nim;10;type mismatch: got (array[0..6, string], int) tinvwhen.nim;6;invalid indentation titer4.nim;2;iterator within for loop context expected +tmethod.nim;2;'method' needs a parameter that has an object type tnamspc.nim;5;undeclared identifier: 'global' tnoop.nim;6;expression 'a()' cannot be called tnot.nim;9;type mismatch @@ -34,4 +35,5 @@ tstmtexp.nim;3;value returned by statement has to be discarded ttempl2.nim;13;undeclared identifier: 'b' ttypelessemptyset.nim;0;Error: internal error: invalid kind for last(tyEmpty) tunderscores.nim;3;invalid token: _ +twrongtupleaccess.nim;4;undeclared field: 'setBLAH' typredef.nim;2;illegal recursion in type 'Uint8' diff --git a/tests/reject/tmethod.nim b/tests/reject/tmethod.nim new file mode 100644 index 000000000..101cabf25 --- /dev/null +++ b/tests/reject/tmethod.nim @@ -0,0 +1,4 @@ + +method m(i: int): int = + return 5 + diff --git a/todo.txt b/todo.txt index 2740908a9..11c40dff7 100755 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,7 @@ +- Tester needs to count failures +- we need a way to disable tests + + High priority (version 0.9.0) ============================= |