Give error when case has an else branch even though all cases are already covered (#9930)
* Give error when case has an else branch even though all cases are already covered. * Don't check for invalid else for type tyFloat..tyFloat128, tyString, tyError * Remove unnecessary else in unittest.nim * Fix sockets.nim
This commit is contained in:
parent
bb85869237
commit
a3c4791e9c
3 changed files with 3 additions and 6 deletions
|
|
@ -807,11 +807,13 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||||
typ = commonType(typ, x.sons[1])
|
typ = commonType(typ, x.sons[1])
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
of nkElse:
|
of nkElse:
|
||||||
chckCovered = false
|
|
||||||
checkSonsLen(x, 1, c.config)
|
checkSonsLen(x, 1, c.config)
|
||||||
x.sons[0] = semExprBranchScope(c, x.sons[0])
|
x.sons[0] = semExprBranchScope(c, x.sons[0])
|
||||||
typ = commonType(typ, x.sons[0])
|
typ = commonType(typ, x.sons[0])
|
||||||
hasElse = true
|
hasElse = true
|
||||||
|
if chckCovered and covered == toCover(c, n.sons[0].typ):
|
||||||
|
localError(c.config, x.info, "invalid else, all cases are already covered")
|
||||||
|
chckCovered = false
|
||||||
else:
|
else:
|
||||||
illFormedAst(x, c.config)
|
illFormedAst(x, c.config)
|
||||||
if chckCovered:
|
if chckCovered:
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,6 @@ when defined(Posix):
|
||||||
of AF_UNIX: result = posix.AF_UNIX
|
of AF_UNIX: result = posix.AF_UNIX
|
||||||
of AF_INET: result = posix.AF_INET
|
of AF_INET: result = posix.AF_INET
|
||||||
of AF_INET6: result = posix.AF_INET6
|
of AF_INET6: result = posix.AF_INET6
|
||||||
else: discard
|
|
||||||
|
|
||||||
proc toInt(typ: SockType): cint =
|
proc toInt(typ: SockType): cint =
|
||||||
case typ
|
case typ
|
||||||
|
|
@ -227,7 +226,6 @@ when defined(Posix):
|
||||||
of SOCK_DGRAM: result = posix.SOCK_DGRAM
|
of SOCK_DGRAM: result = posix.SOCK_DGRAM
|
||||||
of SOCK_SEQPACKET: result = posix.SOCK_SEQPACKET
|
of SOCK_SEQPACKET: result = posix.SOCK_SEQPACKET
|
||||||
of SOCK_RAW: result = posix.SOCK_RAW
|
of SOCK_RAW: result = posix.SOCK_RAW
|
||||||
else: discard
|
|
||||||
|
|
||||||
proc toInt(p: Protocol): cint =
|
proc toInt(p: Protocol): cint =
|
||||||
case p
|
case p
|
||||||
|
|
@ -237,7 +235,6 @@ when defined(Posix):
|
||||||
of IPPROTO_IPV6: result = posix.IPPROTO_IPV6
|
of IPPROTO_IPV6: result = posix.IPPROTO_IPV6
|
||||||
of IPPROTO_RAW: result = posix.IPPROTO_RAW
|
of IPPROTO_RAW: result = posix.IPPROTO_RAW
|
||||||
of IPPROTO_ICMP: result = posix.IPPROTO_ICMP
|
of IPPROTO_ICMP: result = posix.IPPROTO_ICMP
|
||||||
else: discard
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
proc toInt(domain: Domain): cint =
|
proc toInt(domain: Domain): cint =
|
||||||
|
|
@ -853,7 +850,6 @@ proc connect*(socket: Socket, address: string, port = Port(0),
|
||||||
of AF_UNIX: s.sin_family = posix.AF_UNIX
|
of AF_UNIX: s.sin_family = posix.AF_UNIX
|
||||||
of AF_INET: s.sin_family = posix.AF_INET
|
of AF_INET: s.sin_family = posix.AF_INET
|
||||||
of AF_INET6: s.sin_family = posix.AF_INET6
|
of AF_INET6: s.sin_family = posix.AF_INET6
|
||||||
else: nil
|
|
||||||
if connect(socket.fd, cast[ptr TSockAddr](addr(s)), sizeof(s).cint) < 0'i32:
|
if connect(socket.fd, cast[ptr TSockAddr](addr(s)), sizeof(s).cint) < 0'i32:
|
||||||
OSError()
|
OSError()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,6 @@ method testEnded*(formatter: ConsoleOutputFormatter, testResult: TestResult) =
|
||||||
of OK: fgGreen
|
of OK: fgGreen
|
||||||
of FAILED: fgRed
|
of FAILED: fgRed
|
||||||
of SKIPPED: fgYellow
|
of SKIPPED: fgYellow
|
||||||
else: fgWhite
|
|
||||||
styledEcho styleBright, color, prefix, "[", $testResult.status, "] ", resetStyle, testResult.testName
|
styledEcho styleBright, color, prefix, "[", $testResult.status, "] ", resetStyle, testResult.testName
|
||||||
else:
|
else:
|
||||||
rawPrint()
|
rawPrint()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue