Skip to content

Silence warning about reference to free variable#283

Merged
rswgnu merged 1 commit intomasterfrom
remove_reference_to_free_variable
Oct 23, 2022
Merged

Silence warning about reference to free variable#283
rswgnu merged 1 commit intomasterfrom
remove_reference_to_free_variable

Conversation

@matsl
Copy link
Copy Markdown
Collaborator

@matsl matsl commented Oct 12, 2022

What

Silence warnings about referencing free variables.

Before

kotl/klink.el:175:35: Warning: reference to free variable ‘smart-c-include-regexp’
kotl/kotl-mode.el:728:37: Warning: reference to free variable ‘cmpl-last-insert-location’
kotl/kotl-mode.el:729:22: Warning: reference to free variable ‘cmpl-original-string’
kotl/kotl-mode.el:730:20: Warning: assignment to free variable ‘completion-to-accept’
kotl/kview.el:481:13: Warning: assignment to free variable ‘found’
kotl/kview.el:807:54: Warning: Lexical argument shadows the dynamic variable fill-prefix
kotl/kview.el:1399:10: Warning: Variable ‘pos’ left uninitialized
hargs.el:381:33: Warning: reference to free variable ‘Info-current-node’
hargs.el:671:11: Warning: assignment to free variable ‘hargs:reading-symbol’
hargs.el:776:43: Warning: reference to free variable ‘hargs:reading-symbol’
hargs.el:782:42: Warning: reference to free variable ‘Info-current-file-completions’
hargs.el:785:51: Warning: assignment to free variable ‘Info-current-file-completions’
hload-path.el:134:9: Warning: assignment to free variable ‘generated-autoload-file’
hmouse-info.el:43:13: Warning: assignment to free variable ‘Info-complete-menu-buffer’
hmouse-info.el:49:20: Warning: reference to free variable ‘Info-complete-menu-buffer’
hmouse-info.el:238:24: Warning: reference to free variable ‘Info-complete-menu-buffer’
hmouse-info.el:381:30: Warning: reference to free variable ‘Info-complete-menu-buffer’
hmouse-drv.el:438:22: Warning: reference to free variable ‘start-window’
hmouse-sh.el:276:29: Warning: Lexical argument shadows the dynamic variable hmouse-middle-flag
hmouse-sh.el:472:30: Warning: Lexical argument shadows the dynamic variable hmouse-middle-flag
hmouse-sh.el:488:11: Warning: assignment to free variable ‘kmacro-call-mouse-event’
hpath.el:1656:27: Warning: Variable ‘modifier’ left uninitialized
hsettings.el:84:36: Warning: assignment to free variable ‘helm-allow-mouse’
hui-mouse.el:1365:26: Warning: reference to free variable ‘imenu--index-alist’
hui-mouse.el:1406:21: Warning: assignment to free variable ‘imenu--index-alist’
hui-mouse.el:1494:24: Warning: reference to free variable ‘magit-root-section’
hyrolo.el:1104:99: Warning: reference to free variable ‘child’
hyrolo.el:1284:28: Warning: reference to free variable ‘org-roam-directory’
hyrolo.el:1286:11: Warning: reference to free variable ‘org-roam-db-autosync-mode’
hyrolo.el:1844:39: Warning: reference to free variable ‘markdown-regex-header’

After

kotl/kview.el:481:13: Warning: assignment to free variable ‘found’
kotl/kview.el:807:54: Warning: Lexical argument shadows the dynamic variable fill-prefix
kotl/kview.el:1399:10: Warning: Variable ‘pos’ left uninitialized
hmouse-sh.el:277:29: Warning: Lexical argument shadows the dynamic variable hmouse-middle-flag
hmouse-sh.el:473:30: Warning: Lexical argument shadows the dynamic variable hmouse-middle-flag
hpath.el:1656:27: Warning: Variable ‘modifier’ left uninitialized
hyrolo.el:1111:99: Warning: reference to free variable ‘child’

Note

Added some comments below about some specific changes.

@matsl matsl requested a review from rswgnu October 12, 2022 21:33
;;; Private variables
;;; ************************************************************************

(defvar hargs:reading-symbol nil
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not see that this dynamic variable is defined anywhere. Should it not be that?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we really need to add tests of the behavior of each of these variables first to ensure that these defvars do not interfere with any initializations that may take place in other modules/systems, notably for non-Hyperbole variables. Then we can apply the changes and verify things are good via the tests rather than worry about any behavior change, as some of these definitely were meant to perform with dynamic scope in the past.

Copy link
Copy Markdown
Collaborator Author

@matsl matsl Oct 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding test cases is a good idea but might be overkill and I'm not sure it is that straight forward in all cases to actually test the dynamic variables. So could take some time.

The hargs:reading-symbol is a hyperbole variable that I suppose is used as a cache remembering the current symbol that is read so setting it to nil initially should not matter since it would be overwritten all the time. But since it is variable defined by Hyperbole IMHO it is clearer to give it an initial value than to not define it at all!?

For the other defvars they do not initialize them but define them as being in the dynamic scope, and silence the warnings. So should only make the code be more in line with the good old dynamic days. We have used this technique in the past to remove the warnings for the undefined variable that originate from other packages. Is there any way that these defvars could change behavior?

;;; Private variables
;;; ************************************************************************

(defvar hargs:reading-symbol nil
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we really need to add tests of the behavior of each of these variables first to ensure that these defvars do not interfere with any initializations that may take place in other modules/systems, notably for non-Hyperbole variables. Then we can apply the changes and verify things are good via the tests rather than worry about any behavior change, as some of these definitely were meant to perform with dynamic scope in the past.

@matsl matsl force-pushed the remove_reference_to_free_variable branch 2 times, most recently from c1e0b11 to 8a486dd Compare October 17, 2022 20:37
@matsl matsl force-pushed the remove_reference_to_free_variable branch from 8a486dd to 2689fd2 Compare October 22, 2022 22:38
@rswgnu rswgnu merged commit bc5a11f into master Oct 23, 2022
@matsl matsl deleted the remove_reference_to_free_variable branch April 8, 2023 08:52
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.

2 participants