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

Removal of error reporting markers from parameter types #1310

Merged
merged 3 commits into from Aug 12, 2022
Merged

Conversation

Wonseo-C
Copy link
Collaborator

@Wonseo-C Wonseo-C commented Jul 29, 2022

The string returned by getTargetType included error reporting markers, which it shouldn't.

Before this change:
image

After this change:
image

Copy link
Collaborator

@cmnrd cmnrd left a comment

Choose a reason for hiding this comment

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

I don't know the specifics of the TS code generation, but simply using the type id does not seem like the right solution to me. What if the type is time? Or time[]? It seems that getTargetType() does not do exactly what is needed for TS here.

@hokeun
Copy link
Member

hokeun commented Aug 2, 2022

but simply using the type id does not seem like the right solution to me.

I agree. @Wonseo-C, how about debugging to figure out why getTargetType returns a wrong value here? Ideally, we would like to fix the getTargetType function rather than just changing it. Also, does this only happen to the runner? Or does this happen to other .lf programs as well?

@Wonseo-C
Copy link
Collaborator Author

Wonseo-C commented Aug 3, 2022

@cmnrd @hokeun
I tried debugging getTargetType and found that there is some bug.
The function returns parameter.inferredType's toText().
So, there is some bug with toText()'s return value.
image
Also, I found that when I used the toOriginalText(), I got the expected return value "number".
image
How can I fix this problem?

@cmnrd
Copy link
Collaborator

cmnrd commented Aug 3, 2022

@petervdonovan could you have a look at this? Is it save to just use toOriginalText() here? It looks like the code tagging is breaking things in TypeScript.

@Wonseo-C
Copy link
Collaborator Author

Wonseo-C commented Aug 9, 2022

@petervdonovan could you have a look at this? Is it save to just use toOriginalText() here? It looks like the code tagging is breaking things in TypeScript.

I changed getTargetType()'s return value toOriginalText()

@Wonseo-C Wonseo-C requested a review from cmnrd August 9, 2022 00:53
@petervdonovan
Copy link
Collaborator

petervdonovan commented Aug 9, 2022

Sorry for missing @cmnrd's comment.

Since I don't know the full motivation behind this change, it is difficult for me to comment on whether it is necessary. It can cause slight regressions in the error reporting functionality of the language server, which needs these tags in order to report errors on the correct lines in VS Code.

A possible alternative would be to strip the CodeMap tags out downstream, as is done here using CodeMap.fromGeneratedCode(someToTextOutputWithTags).generatedCode. This might not be the most elegant solution, but I think it would be the right choice if the result of getTargetType is only wrong for a few specific cases. (I mean, if it is fine for the code generators, but not what we want when using it for something else.)

@lhstrh
Copy link
Member

lhstrh commented Aug 10, 2022

@petervdonovan: the problem is that the type of the parameter instead of returning something like string or number would return a much longer string with additional markers in it used for error reporting. I think this is a legitimate bug, and the text referenced in the method should be the original one, not the modified one. I'm not quite sure how this fix would affect error reporting...

Are you suggesting that we replace the line that says type.toOriginalText() with CodeMap.fromGeneratedCode(type).generatedCode? If you could make a concrete code suggestion in the Files changed, that would be great.

@lhstrh lhstrh changed the title Change the part of getting paramType Fix to address leaking of error reporting markers into argument types Aug 10, 2022
@lhstrh lhstrh changed the title Fix to address leaking of error reporting markers into argument types Fix to address leaking of error reporting markers into parameter types Aug 10, 2022
@Wonseo-C
Copy link
Collaborator Author

Wonseo-C commented Aug 11, 2022

Are you suggesting that we replace the line that says type.toOriginalText() with CodeMap.fromGeneratedCode(type).generatedCode? If you could make a concrete code suggestion in the Files changed, that would be great.

@lhstrh Does this mean that we'll use CodeMap.fromGeneratedCode(type).generatedCode like under the screenshot?
I did debug like this, and then I got the value of "number\n", not "number".
스크린샷 2022-08-11 오후 2 15 53

And sorry for the bad readability. I added the code link in the main comment..!

@petervdonovan
Copy link
Collaborator

Sorry for the late response...

Are you suggesting that we replace the line that says type.toOriginalText() with CodeMap.fromGeneratedCode(type).generatedCode? If you could make a concrete code suggestion in the Files changed, that would be great.

That is not quite what I meant. If we did that, it would be equivalent to just using toOriginalText, except that it is more complicated because it puts the CodeMap.Correspondence tags in and then takes them out again.

I cannot suggest a change in the Files changed because my suggestion applied only to the code that originally motivated this PR. I do not know why you wanted to change getTargetType, but I guessed that it was because somewhere else in the code base, the CodeMap.Correspondence tags were causing problems. If the tags are causing problems elsewhere, then the change I suggested would be a workaround.

I think this is a legitimate bug, and the text referenced in the method should be the original one, not the modified one.

I'm not sure why this would be the case. The philosophy behind my liberal use of these tags is that the primary purpose of the functions that convert EObjects to text is for code generation, and that all generated code copied verbatim from the source should have a mapping. To access the contents of the EObject, we can just directly call its getters, right? It strikes me as slightly hacky to use the functions related to code generation to stringify these objects, and then use regexes and string functions to analyze them -- sure, we do it, and I probably have done it too, but it isn't something we should aspire to because it is a heuristic-based approach that creates weird bugs and corner cases.

That said, this has been a lot of discussion over a relatively harmless change. I am happy to see this PR get merged if that's necessary in order to make progress.

@lhstrh
Copy link
Member

lhstrh commented Aug 12, 2022

I guess the real issue is that the markers should associate not with a parameter type but with a declaration that uses it... I agree that it would be reasonable to merge this in order to make progress... This can always be revised at a later time.

@lhstrh lhstrh changed the title Fix to address leaking of error reporting markers into parameter types Removal of error reporting markers from parameter types Aug 12, 2022
@lhstrh lhstrh added the bugfix label Aug 12, 2022
@lhstrh lhstrh merged commit 773d8f9 into master Aug 12, 2022
@lhstrh lhstrh deleted the ts-customArg branch August 12, 2022 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants