Comments (10)
Hi, @kaleidawave! Couple of questions on implementing this;
- Where will the
position
field from anEvent
be used? I noticed that theReturnedTypeDoesNotMatch
already has some position information and uses it while reporting, so I'm unclear on what this change would enable. - Do you envision adding more metadata about
Event
s in the future? Trying to evaluate whether it's worth defining a struct and adding that to each variant - seems premature at this stage vs. just directly addingposition
fields and refactoring later, if needed. - The
Event
variants are mixed where most are struct-like, but some are not (e.g.SetsVariable
andThrow
). Is it worth refactoring to struct-like variants across the board or would adding an unnamedSpan
field be acceptable for those tuple-like variants?
Appreciate any and all guidance - thanks!
from ezno.
Hey @NitantP, thanks for the interest. Hopefully the following answers your questions
-
So currently the
position
field inReturnedTypeDoesNotMatch
just points to the return type annotation. What would be ideal is for that it to also contain the positions of the offendingreturn
statements. Getting these positions for these errors would be really simple if they were held on return events. This sort of thing is already implemented forAssignmentError::DoesNotMeetConstraint
ezno/checker/src/context/mod.rs
Lines 1390 to 1394 in 7cf648d
ezno/checker/src/diagnostics.rs
Lines 377 to 392 in 7cf648d
-
and 3. Can't think of any more metadata that is needed on
Event
rn, so just aSpan
on each should be fine. I see that SetsVariable and Throw are currently the only two unnamed variants, feel free to make the named variants like the others!
I am hoping it shouldn't be too difficult to start on, I am happy to help with any problems that arise if you decide to give it go! Note: you do not have to fully connect the errors up, I am thinking it might need another change for it to work perfectly. But if all you could get events setup with a position for each then it would be really useful for now and future ideas!
from ezno.
Just a heads up @NitantP. #61 changes the structure of positions a lot so might be worth waiting for that to merge before starting
from ezno.
@wzwywx awesome! Thanks for attempting it, if you do make any progress (working or not) would be great to put in a PR anyway as I am happy to help finish it if you make a start.
Might be worth reading the title 😅 but yes you have run into the exact problem!
What I would start with is adding a field to the return event variant, (events/mod.ts:68)
Return {
returned: TypeId,
// \/ field you should add \/
position: SpanWithSource
}
then you will see rust error a bunch and you just have to follow those until it compiles again (so you will probably have to do things like modify return_value
(context/environment.rs:713) to take a position via a parameter and modify the synthesis code to give that position when it calls that).
Then once you have that field you can go back and get the diagnostic working!
And if you find that okay you can add a position field to every variant as I need it for other diagnostics 😀
Also no worries @NitantP
from ezno.
Hi @wzwywx - please feel free to submit a PR if you'd like. I haven't been able to make the progress I intended to given circumstances, so you may be in a better position to see this through.
Ah, I see. No worries @NitantP ; hopefully your circumstances are improving and I wish you well.
from ezno.
Understood - thanks, @kaleidawave!
from ezno.
Hi @NitantP #61 has been merged. So the repo code should be in a good state to work on this. Some updates:
- The positions should be
source_map::SpanWithSource
(aka have both a position and a file). This is the same as diagnostics/errors so there should be some good examples of creating them - Since writing the issue I have reworked the return checking. (aka a function annotated as
function x(): number
, check that all returns are subtypes ofnumber
). Once events have positions, if you want to add the diagnostics you can check outezno/checker/src/events/helpers.rs
Line 17 in 88fc8e4
Specifically there is a place which would be ideal for using a position here
ezno/checker/src/events/helpers.rs
Line 58 in 88fc8e4
LMK if there are any more questions :)
from ezno.
Hello, @kaleidawave. I'm trying to solve this issue on my end just to practice my Rust skills (no PR since I presume NitantP is still working on this issue.)
I understand how to modify the diagnostic messages and alter the ReturnedTypeDoesNotMatch
to have the position for the return location.
But any thoughts on how to get the position of the location the value is returned?
I can see that get_return_from_events
iterates through the events, but the pertinent event, Event::Return
only stores a &TypeId
and no position for when the event was triggered.
ezno/checker/src/events/helpers.rs
Lines 23 to 24 in 88fc8e4
from ezno.
Hi @wzwywx - please feel free to submit a PR if you'd like. I haven't been able to make the progress I intended to given circumstances, so you may be in a better position to see this through.
from ezno.
from ezno.
Related Issues (20)
- Add more specification tests HOT 2
- Add binary type caching back and think about TypeId HOT 1
- More configuration and per file options/configuration
- Implement destructuring assignment (declaration works already)
- Function .bind. Then .call and .apply
- Record mutated variables / objects that might be mutated by a unknown loop or function call HOT 1
- Check JS Doc / other type annotations HOT 1
- Read from imports HOT 6
- For / while loops
- Expected type during value synthesis HOT 1
- I wonder if this project has matured to this point yet?
- Multiple files as entry point HOT 1
- Exporting type from another file
- Handling explicit file extension (Node16 + NodeNext) HOT 4
- Diagnostics container as a trait / callback
- [feature-request] Is it possible to integrate this into compile time check? HOT 1
- Binary operator checking
- Parse error with comment in object literal HOT 2
- Add an option NOT to bind the value of `this` to a returned value when getting a property to account for destructuring
- Fix and figure out how multiple properties should be represented
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ezno.