Warning on `if a == true then` constructions.
Pull-Request: #2520
Reviewed-by: Jean-Christophe Beaupré <jcbrinfo.public@gmail.com>
if "NIT_TESTING".environ == "true" then exit 0
opts.parse args
-if not opts.errors.is_empty or opts.help.value == true then
+if not opts.errors.is_empty or opts.help.value then
print opts.errors.join("\n")
print "Usage: benitlux_daily [Options]"
opts.usage
fun easy_setopt(opt: CURLOption, obj: Object): CURLCode
do
if obj isa Int then return native_setopt_int(opt, obj)
- if obj isa Bool and obj == true then return native_setopt_int(opt, 1)
- if obj isa Bool and obj == false then return native_setopt_int(opt, 0)
+ if obj == true then return native_setopt_int(opt, 1)
+ if obj == false then return native_setopt_int(opt, 0)
if obj isa String then return native_setopt_string(opt, obj)
if obj isa FileWriter then return native_setopt_file(opt, obj._file.as(not null))
if obj isa CURLSList then return native_setopt_slist(opt, obj)
var r = new Array[String]
var cursor = self
loop
- if native_data_reachable(cursor) != true then break
+ if not native_data_reachable(cursor) then break
r.add(native_data(cursor))
cursor = native_next(cursor)
end
var socket: nullable TCPStream = null
# Is this connection connected?
- fun connected: Bool do return socket != null and socket.connected == true
+ fun connected: Bool do return socket != null and socket.connected
# `BinarySerializer` used to send data to this client through `socket`
var writer: BinarySerializer is noinit
var method = http_request.method
var response: HttpResponse
- if is_teapot == true then
+ if is_teapot then
response = new HttpResponse(418)
response.body = "I'm a teapot!\n"
response.header["Content-Type"] = "text"
abort
end
- if v.modelbuilder.toolcontext.opt_no_color.value == true then
+ if v.modelbuilder.toolcontext.opt_no_color.value then
sys.stderr.write("Runtime error: {message} ({location.file.filename}:{location.line_start})\n")
else
sys.stderr.write("{location}: Runtime error: {message}\n{location.colored_line("0;31")}\n")
bad_conception_elements.add(new FeatureEnvy(phase))
bad_conception_elements.add(new LongMethod(phase))
for bad_conception_element in bad_conception_elements do
- if bad_conception_element.collect(self.mclassdef,phase.toolcontext.modelbuilder) == true then array_badconception.add(bad_conception_element)
+ if bad_conception_element.collect(self.mclassdef,phase.toolcontext.modelbuilder) then array_badconception.add(bad_conception_element)
end
end
if anchor == null then anchor = sub # UGLY: any anchor will work
var resolved_sub = sub.anchor_to(mmodule, anchor)
var res = resolved_sub.collect_mclasses(mmodule).has(sup.mclass)
- if res == false then return false
+ if not res then return false
if not sup isa MGenericType then return true
var sub2 = sub.supertype_to(mmodule, anchor, sup.mclass)
assert sub2.mclass == sup.mclass
var sub_arg = sub2.arguments[i]
var sup_arg = sup.arguments[i]
res = sub_arg.is_subtype(mmodule, anchor, sup_arg)
- if res == false then return false
+ if not res then return false
# The two new lines
res = sup_arg.is_subtype(mmodule, anchor, sub_arg)
- if res == false then return false
+ if not res then return false
# End of the two new lines
end
return true
var callsite = n.callsite
if callsite != null then
self.total_call += 1
- if callsite.recv_is_self == true then self.total_self_call += 1
+ if callsite.recv_is_self then self.total_self_call += 1
end
end
end
if anchor == null then anchor = sub # UGLY: any anchor will work
var resolved_sub = sub.anchor_to(mmodule, anchor)
var res = resolved_sub.collect_mclasses(mmodule).has(sup.mclass)
- if res == false then return false
+ if not res then return false
if not sup isa MGenericType then return true
var sub2 = sub.supertype_to(mmodule, anchor, sup.mclass)
assert sub2.mclass == sup.mclass
var sub_arg = sub2.arguments[i]
var sup_arg = sup.arguments[i]
res = sub_arg.is_subtype(mmodule, anchor, sup_arg)
- if res == false then return false
+ if not res then return false
end
return true
end
if mtype == null or mtype2 == null then return
+ if mtype == v.type_bool(self) and (n_expr2 isa AFalseExpr or n_expr2 isa ATrueExpr) then
+ v.modelbuilder.warning(self, "useless-truism", "Warning: useless comparison to a Bool literal.")
+ end
+
if not mtype2 isa MNullType then return
v.check_can_be_null(n_expr, mtype)
var mask = sub.mclass.vtable.mask
var res = inter_is_subtype_ph(super_id, mask, sub.mclass.vtable.internal_vtable)
- if res == false then return false
+ if not res then return false
# sub and sup can be generic types, each argument of generics has to be tested
if not sup isa MGenericType then return true
var sub_arg = sub2.arguments[i]
var sup_arg = sup.arguments[i]
var res2 = is_subtype(sub_arg, sup_arg)
- if res2 == false then return false
+ if not res2 then return false
end
return true
end
--- /dev/null
+warn_truism.nit:18,4--12: Warning: useless comparison to a Bool literal.
+warn_truism.nit:19,9--18: Warning: useless comparison to a Bool literal.
+warn_truism.nit:20,10--26: Warning: useless comparison to a Bool literal.
+warn_truism.nit:20,33--41: Warning: useless comparison to a Bool literal.
assert postgres_ntuples: result.ntuples == 2 else print_error db.error
assert postgres_nfields: result.nfields == 3 else print_error db.error
assert postgres_fname: result.fname(0) == "aname" else print_error db.error
-assert postgres_isnull: result.is_null(0,0) == false else print_error db.error
+assert postgres_isnull: not result.is_null(0,0) else print_error db.error
assert postgres_value: result.value(0,0) == "Whale" else print_error db.error
var cols: Int = result.nfields
assert postgres_nfields: result.nfields == 4 else print_error db.error
assert postgres_fname: result.fname(0) == "uname" else print_error db.error
-assert postgres_isnull: result.is_null(0,0) == false else print_error db.error
+assert postgres_isnull: not result.is_null(0,0) else print_error db.error
assert postgres_value: result.value(0,0) == "Bob" else print_error db.error
assert drop_table: db.execute("DROP TABLE users_{db_suffix}") else print db.error
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import core::kernel
+
+var a = true
+if a == true then end
+var b = a != false
+var c = ((a or b) == false) and b != true
+
+# only warn the common case (not those)
+if true == a then end
+if a == (true) then end
+
+# dont warn if operand 1 is not a bool
+var o: nullable Bool = a
+if o == true then end
+if o or else false then end