fixes a regression about static object case variant checking

This commit is contained in:
Araq
2018-04-06 13:01:24 +02:00
parent 0872e7a27e
commit 824092be31
2 changed files with 33 additions and 1 deletions

View File

@@ -77,7 +77,9 @@ proc semConstrField(c: PContext, flags: TExprFlags,
proc caseBranchMatchesExpr(branch, matched: PNode): bool =
for i in 0 .. branch.len-2:
if exprStructuralEquivalent(branch[i], matched):
if branch[i].kind == nkRange:
if overlap(branch[i], matched): return true
elif exprStructuralEquivalent(branch[i], matched):
return true
return false

View File

@@ -49,4 +49,34 @@ var t = stack.pop()
echo "came here"
# another regression:
type
LexerToken* = enum
ltYamlDirective, ltYamlVersion, ltTagDirective, ltTagShorthand,
ltTagUri, ltUnknownDirective, ltUnknownDirectiveParams, ltEmptyLine,
ltDirectivesEnd, ltDocumentEnd, ltStreamEnd, ltIndentation, ltQuotedScalar,
ltScalarPart, ltBlockScalarHeader, ltBlockScalar, ltSeqItemInd, ltMapKeyInd,
ltMapValInd, ltBraceOpen, ltBraceClose, ltBracketOpen, ltBracketClose,
ltComma, ltLiteralTag, ltTagHandle, ltAnchor, ltAlias
const tokensWithValue =
{ltScalarPart, ltQuotedScalar, ltYamlVersion, ltTagShorthand, ltTagUri,
ltUnknownDirective, ltUnknownDirectiveParams, ltLiteralTag, ltAnchor,
ltAlias, ltBlockScalar}
type
TokenWithValue = object
case kind: LexerToken
of tokensWithValue:
value: string
of ltIndentation:
indentation: int
of ltTagHandle:
handle, suffix: string
else: discard
proc sp(v: string): TokenWithValue =
# test.nim(27, 17) Error: a case selecting discriminator 'kind' with value 'ltScalarPart' appears in the object construction, but the field(s) 'value' are in conflict with this value.
TokenWithValue(kind: ltScalarPart, value: v)
let a = sp("test")