Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a couple small "code" bugs #3482

Merged
merged 2 commits into from
Sep 18, 2024
Merged

Conversation

d-torrance
Copy link
Member

We fix two little code bugs I noticed:

First, we previously assumed that the given FilePosition object would include a stopping position, which isn't the case for some things (like outputs of locate(DocumentTag):

i1 : locate makeDocumentTag (ideal, List)

o1 = /usr/share/Macaulay2/Macaulay2Doc/functions/ideal-doc.m2:42:0

o1 : FilePosition

i2 : code oo
stdio:2:4:(3): error: array index 3 out of bounds 0 .. 2

So we assume that the stopping is the same as the starting position, which maybe isn't great, but at least there's no more error:

i1 : locate makeDocumentTag (ideal, List)

o1 = src/macaulay2/M2/M2/Macaulay2/packages/Macaulay2Doc/functions/ideal-doc.m2:42:0

o1 : FilePosition

i2 : code oo

o2 = src/macaulay2/M2/M2/Macaulay2/packages/Macaulay2Doc/functions/ideal-doc.m2:42:0: --source code:
     document { 

The other bug is very very minor. Suppose, for some crazy reason, we write some Macaulay2 code in a file named something that matches the regex "startup.m2.in$", e.g., "startupxm2xin". If we load it and call code on something from it, then it will give us something from the actual startup.m2.in:

i1 : get "startupxm2xin"

o1 = f = x -> x^2

i2 : load "startupxm2xin"

i3 : code f

o3 = startupxm2xin:1:4-1:12: --source code:
     -- -*- coding: utf-8 -*-

If we properly escape the dots, then it works as expected:

i3 : code f

o3 = startupxm2xin:1:4-1:12: --source code:
     f = x -> x^2

M2/Macaulay2/m2/code.m2 Outdated Show resolved Hide resolved
We previously assumed there would always be a stopping position.
Otherwise, we could theoretically load a file named something like
"startupxm2xin", call "code" on something from that file, and
end up with some code from startup.m2.in.
@mahrud
Copy link
Member

mahrud commented Sep 18, 2024

The second bug is actually hilarious 😂

@d-torrance d-torrance merged commit 2e00075 into Macaulay2:development Sep 18, 2024
5 checks passed
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