Skip to content

Conversation

@timotheecour
Copy link
Member

@timotheecour timotheecour commented Oct 21, 2020

too verbose by default but very useful when you need to figure out where symbols are declared without guesswork.
(also avoids having to instrument compiler when chasing those things, eg see https://github.com/nim-lang/Nim/pull/15660/files#diff-083ab8ee8fb7c645dd951c50f3b05f3fbb27605001375f4870a1a0ddc21b7e04R233)

example

type Foo = ref object
discard $Foo()

nim r --listfullpaths --declaredlocs main

/Users/timothee/git_clone/nim/timn/tests/nim/all/t11164.nim(5, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11164.nim(16, 11) Error: type mismatch: got <Foo>
but expected one of:
proc `$`(s: WideCString): string [declared in /Users/timothee/git_clone/nim/Nim_prs/lib/system/widestrs.nim(215, 6)]
  first type mismatch at position: 1
  required type for s: WideCString [declared in /Users/timothee/git_clone/nim/Nim_prs/lib/system/widestrs.nim(60, 5)]
  but expression 'Foo()' is of type: Foo [declared in /Users/timothee/git_clone/nim/timn/tests/nim/all/t11164.nim(15, 8)]
proc `$`(t: typedesc): string [declared in /Users/timothee/git_clone/nim/Nim_prs/lib/system/dollars.nim(78, 6)]
  first type mismatch at position: 1
  required type for t: typedesc [declared in /Users/timothee/git_clone/nim/Nim_prs/lib/system/dollars.nim(78, 11)]
  but expression 'Foo()' is of type: Foo [declared in /Users/timothee/git_clone/nim/timn/tests/nim/all/t11164.nim(15, 8)]
...

note:

honors --listfullpaths (ie same logic as what's used in listfullpaths is used to display paths; note that the logic used for listfullpaths could be improved but that's out of scope for this PR)

future work

  • apply same treatment to type mismatch: got <... errors, eg:
type Foo = ref object
var b: string = Foo()

=> #15673

@Araq
Copy link
Member

Araq commented Oct 21, 2020

Superb work, thanks!

@Araq Araq merged commit 05752cd into nim-lang:devel Oct 21, 2020
@alaviss
Copy link
Collaborator

alaviss commented Oct 21, 2020

I think this is a bit too verbose. Would a --hint[DeclaredAt] which output something like this:

/Users/timothee/git_clone/nim/timn/tests/nim/all/t11164.nim(5, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/tests/nim/all/t11164.nim(16, 11) Error: type mismatch: got <Foo>
but expected one of:
/Users/timothee/git_clone/nim/Nim_prs/lib/system/widestrs.nim(215, 6) Hint: Symbol widestrs.`$` was declared here [DeclaredAt]
proc `$`(s: WideCString): string
  first type mismatch at position: 1
  required type for s: WideCString
  but expression 'Foo()' is of type: Foo
/Users/timothee/git_clone/nim/Nim_prs/lib/system/dollars.nim(78, 6) Hint: Symbol dollars.`$` was declared here [DeclaredAt]
proc `$`(t: typedesc): string
  first type mismatch at position: 1
  required type for t: typedesc
  but expression 'Foo()' is of type: Foo
...

works?

It'd be more uniform like this IMO.

EDIT: lol Araq merged right after I post my feedback.

@timotheecour
Copy link
Member Author

you don't have to turn it on by default, but when you're trying to debug some error, the declared locations help, even for the types (as done here: https://github.com/nim-lang/Nim/pull/15660/files#diff-083ab8ee8fb7c645dd951c50f3b05f3fbb27605001375f4870a1a0ddc21b7e04R233 where code was instrumented). That said, I'd be happy with adding this:

# same as was done in this PR:
--declaredlocs and --declaredlocs:[on|off]

# new:
--declaredlocs:toplevel 
proc `$`(t: typedesc): string [declared in /Users/timothee/git_clone/nim/Nim_prs/lib/system/dollars.nim(78, 6)]
  first type mismatch at position: 1
  required type for t: typedesc
  but expression 'Foo()' is of type: Foo

which is less verbose. Note that [declared in ...] is the same format as used in other contexts.

@timotheecour timotheecour deleted the pr_sigmatch_candidates_loc branch October 21, 2020 16:57
@alaviss
Copy link
Collaborator

alaviss commented Oct 21, 2020

I was looking for a more uniforming style via the use of hints since it'd allows editors that integrate with Nim's output to easily implements jumps-to-file.

@timotheecour
Copy link
Member Author

timotheecour commented Oct 21, 2020

I was looking for a more uniforming style via the use of hints since it'd allows editors that integrate with Nim's output to easily implements jumps-to-file.

that's a separate issue, and IMO editors whose jump-to-file depends on presence of a hint/hint-like formatting should be fixed, and wouldn't even work with some other messages eg assert failures:

Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t11165.nim(6, 12) `false`  [AssertionDefect]

Require a location in messages to only appear at start of a line would also prevent showing declarations for types in an effective way as shown above.

Editors should handle location everywhere, not just at beginning of line, that being said, see #690 on the topic of making jump-to-file easier on editors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants