diff options
author | Araq <rumpf_a@web.de> | 2017-12-15 16:46:45 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-12-15 16:46:45 +0100 |
commit | 0ab28d5e8ed0f6689cfb3167f4ff93ffdf53cb75 (patch) | |
tree | 45b81c0842bbaa6b6e99eda69d70d5da956639e2 | |
parent | b73bb911a909d62ef0ffcdb7b38c28fe5659fb23 (diff) | |
parent | 0d744cccc2ecbaed6ba5663dba66bdd9a0f174b2 (diff) | |
download | Nim-0ab28d5e8ed0f6689cfb3167f4ff93ffdf53cb75.tar.gz |
Merge branch 'Veladus-issue-6805' into devel
-rw-r--r-- | compiler/ast.nim | 3 | ||||
-rw-r--r-- | compiler/semstmts.nim | 10 | ||||
-rw-r--r-- | compiler/semtypes.nim | 1 | ||||
-rw-r--r-- | lib/system.nim | 2 |
4 files changed, 14 insertions, 2 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 5bf4184c9..5b923acb2 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -639,7 +639,8 @@ type mEqIdent, mEqNimrodNode, mSameNodeType, mGetImpl, mNHint, mNWarning, mNError, mInstantiationInfo, mGetTypeInfo, mNGenSym, - mNimvm, mIntDefine, mStrDefine, mRunnableExamples + mNimvm, mIntDefine, mStrDefine, mRunnableExamples, + mException # things that we can evaluate safely at compile time, even if not asked for it: const diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index e01f867fa..c85de35cd 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -729,6 +729,16 @@ proc semRaise(c: PContext, n: PNode): PNode = var typ = n.sons[0].typ if typ.kind != tyRef or typ.lastSon.kind != tyObject: localError(n.info, errExprCannotBeRaised) + + # check if the given object inherits from Exception + var base = typ.lastSon + while true: + if base.sym.magic == mException: + break + if base.lastSon == nil: + localError(n.info, "raised object of type $1 does not inherit from Exception", [typ.sym.name.s]) + return + base = base.lastSon proc addGenericParamListToScope(c: PContext, n: PNode) = if n.kind != nkGenericParams: illFormedAst(n) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index b633c87ab..f2fda3453 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1620,6 +1620,7 @@ proc processMagicType(c: PContext, m: PSym) = rawAddSon(m.typ, newTypeS(tyNone, c)) of mPNimrodNode: incl m.typ.flags, tfTriggersCompileTime + of mException: discard else: localError(m.info, errTypeExpected) proc semGenericConstraints(c: PContext, x: PType): PType = diff --git a/lib/system.nim b/lib/system.nim index e66699ae4..83e87683a 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -463,7 +463,7 @@ type line*: int ## line number of the proc that is currently executing filename*: cstring ## filename of the proc that is currently executing - Exception* {.compilerproc.} = object of RootObj ## \ + Exception* {.compilerproc, magic: "Exception".} = object of RootObj ## \ ## Base exception class. ## ## Each exception has to inherit from `Exception`. See the full `exception |