Add hints when a class name cause an error.
Basically 3 cases are considered: spellign, bad visibility and not imported. e.g.
~~~
Error: class `Fail` not found in module `error_unk_class`.
Error: class `Boolean` not found in module `error_unk_class`. Did you mean `Bool`?
Error: class `core::list::ListNode` not visible in module `error_unk_class`.
Error: class `POSet` not found in module `error_unk_class`. Maybe import `poset`?
~~~
Pull-Request: #2034
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
end
end
- # If everything fail, then give up :(
+ # If everything fail, then give up with class by proposing things.
+ #
+ # TODO Give hints on formal types (param and virtual)
+ # TODO How to move this in a libified autonomous code?
+
+ var all_classes = model.get_mclasses_by_name(name)
+
+ # Look for imported but invisible classes.
+ if all_classes != null then for c in all_classes do
+ if not mmodule.in_importation <= c.intro_mmodule then continue
+ error(ntype, "Error: class `{c.full_name}` not visible in module `{mmodule}`.")
+ return null
+ end
+
+ # Look for not imported but known classes from importable modules
+ var hints = new Array[String]
+ if all_classes != null then for c in all_classes do
+ if c.intro_mmodule.in_importation <= mmodule then continue
+ if c.visibility <= private_visibility then continue
+ hints.add "`{c.intro_mmodule.full_name}`"
+ end
+ if hints.not_empty then
+ error(ntype, "Error: class `{name}` not found in module `{mmodule}`. Maybe import {hints.join(",", " or ")}?")
+ return null
+ end
+
+ # Look for classes with an approximative name.
+ var bestd = name.length / 2 # limit up to 50% name change
+ for c in model.mclasses do
+ if not mmodule.in_importation <= c.intro_mmodule then continue
+ if not mmodule.is_visible(c.intro_mmodule, c.visibility) then continue
+ var d = name.levenshtein_distance(c.name)
+ if d <= bestd then
+ if d < bestd then
+ hints.clear
+ bestd = d
+ end
+ hints.add "`{c.name}`"
+ end
+ end
+ if hints.not_empty then
+ error(ntype, "Error: class `{name}` not found in module `{mmodule}`. Did you mean {hints.join(",", " or ")}?")
+ return null
+ end
+
error(ntype, "Error: class `{name}` not found in module `{mmodule}`.")
return null
end
var mlazypropdef = self.mlazypropdef
if mlazypropdef != null then
- mlazypropdef.static_mtype = modelbuilder.model.get_mclasses_by_name("Bool").first.mclass_type
+ mlazypropdef.static_mtype = mmodule.bool_type
end
check_repeated_types(modelbuilder)
end
# This file is part of NIT ( http://www.nitlanguage.org ).
#
-# Copyright 2004-2008 Jean Privat <jean@pryen.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
# See the License for the specific language governing permissions and
# limitations under the License.
-var i = new Canard
+var i
+i = new Fail
+i = new Boolean
+i = new ListNode
+i = new POSet
i.output
--- /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 poset
+import error_unk_class
-error_unk_class.nit:17,13--18: Error: class `Canard` not found in module `error_unk_class`.
+error_unk_class.nit:16,9--12: Error: class `Fail` not found in module `error_unk_class`.
+error_unk_class.nit:17,9--15: Error: class `Boolean` not found in module `error_unk_class`. Did you mean `Bool`?
+error_unk_class.nit:18,9--16: Error: class `core::list::ListNode` not visible in module `error_unk_class`.
+error_unk_class.nit:19,9--13: Error: class `POSet` not found in module `error_unk_class`. Did you mean `Set`?
--- /dev/null
+error_unk_class.nit:16,9--12: Error: class `Fail` not found in module `error_unk_class`.
+error_unk_class.nit:17,9--15: Error: class `Boolean` not found in module `error_unk_class`. Did you mean `Bool`?
+error_unk_class.nit:18,9--16: Error: class `core::list::ListNode` not visible in module `error_unk_class`.
+error_unk_class.nit:19,9--13: Error: class `POSet` not found in module `error_unk_class`. Maybe import `poset`?