-
-
Notifications
You must be signed in to change notification settings - Fork 0
implement missing libraries #21
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
base: main
Are you sure you want to change the base?
Conversation
The infinite loop was caused by the catch target not being popped after entering it. This caused all exceptions thrown within the catch block to just jump to the start of the block, thus infinitley calling itself instead of just erroring out
This comment was marked as resolved.
This comment was marked as resolved.
BREAKING: Made `returnType` required for bindings BREAKING: Added a custom lint rule to ban `toString()` on any instances of `Type`
- DateTime lib is still incomplete BREAKING: Structs are now generic and require a toDart and fromDart function upon creation (does not apply to shallow structs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements several missing standard library modules for the dscript language, introducing comprehensive support for filesystem operations, HTTP requests, JSON handling, UTF-8 encoding, Base64 encoding, and utility functions for lists, maps, and dynamic values.
- Refactored the
Structtype system to support typed conversion between DSL and Dart objects - Implemented new standard library modules:
fs,http,json,utf8,base64,list,map, anddynamic - Enhanced the
RuntimeBindingsystem with middleware support and improved parameter handling - Added comprehensive documentation and custom linting rules
Reviewed Changes
Copilot reviewed 47 out of 51 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
lib/src/types.dart |
Enhanced Struct type with generic support and predefined structs for HTTP responses, JSON, DateTime, and Duration |
lib/src/stdlib/*.dart |
Implemented new standard library modules with comprehensive functionality |
lib/src/bindings.dart |
Refactored RuntimeBinding with middleware support and improved parameter validation |
lib/src/contract_builder.dart |
Updated contract builder to support new parameter naming and return type specification |
pubspec.yaml |
Added new dependencies (dio, custom_lint) and removed unused stack dependency |
docs/ |
Updated documentation with comprehensive standard library reference |
custom_lints/ |
Added custom linting rules to prevent type.toString() usage in web builds |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| name: 'add', | ||
| function: (List<dynamic> list, dynamic element) => list.add(element), | ||
| positionalParams: { | ||
| 'list': ListType(elementType: const DynamicType()), |
Copilot
AI
Aug 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'add' binding is missing the 'element' parameter in positionalParams. This will cause a runtime error when validating arguments since the function expects 2 parameters but only 1 is declared.
| 'list': ListType(elementType: const DynamicType()), | |
| 'list': ListType(elementType: const DynamicType()), | |
| 'element': const DynamicType(), |
| name: 'remove', | ||
| function: (List<dynamic> list, dynamic element) => list.remove(element), | ||
| positionalParams: { | ||
| 'list': ListType(elementType: const DynamicType()), |
Copilot
AI
Aug 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'remove' binding is missing the 'element' parameter in positionalParams. This will cause a runtime error when validating arguments since the function expects 2 parameters but only 1 is declared.
| 'list': ListType(elementType: const DynamicType()), | |
| 'list': ListType(elementType: const DynamicType()), | |
| 'element': const DynamicType(), |
| value, | ||
| 'value', | ||
| 'Value must be a collection or string to get length.', | ||
| ); |
Copilot
AI
Aug 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider using a more efficient type check pattern like 'value.length' directly with try-catch, which would avoid multiple type checks and leverage Dart's dynamic dispatch.
| ); | |
| try { | |
| return value.length; | |
| } catch (e) { | |
| throw ArgumentError.value( | |
| value, | |
| 'value', | |
| 'Value must have a length property.', | |
| ); | |
| } |
| store(frame, index, stack.removeLast()); | ||
|
|
||
| // pop this catch target to avoid infinite loops if the catch block throws again | ||
| if (catchTargets.isNotEmpty) catchTargets.removeLast(); |
Copilot
AI
Aug 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment and logic suggest removing catch targets unconditionally during exception handling, but this could break proper exception handling flow. The catch target should only be removed when the catch block completes successfully, not during exception processing.
| if (catchTargets.isNotEmpty) catchTargets.removeLast(); | |
| // Do not remove the catch target here; it should only be removed when the catch block completes successfully (in endTry). | |
|
|
||
| static Map<String, dynamic> _shallowFromDart<T>(T obj) { | ||
| throw UnimplementedError( | ||
| r'Cannot convert Dart object to shallow struct. Use `$Type.lookup` to get the resolved struct and call `fromDart` on it.'); |
Copilot
AI
Aug 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message references '$Type.lookup' method which may not exist or be accessible to users. Consider providing a more actionable error message with the correct method name or approach.
| r'Cannot convert Dart object to shallow struct. Use `$Type.lookup` to get the resolved struct and call `fromDart` on it.'); | |
| 'Cannot convert shallow struct to Dart object. Ensure you are using a fully resolved struct and call `toDart` on it.'); | |
| } | |
| static Map<String, dynamic> _shallowFromDart<T>(T obj) { | |
| throw UnimplementedError( | |
| 'Cannot convert Dart object to shallow struct. Ensure you are using a fully resolved struct and call `fromDart` on it.'); |
| final contents = dir.listSync(); | ||
| return contents | ||
| .whereType<File>() | ||
| .map((file) => file.path) |
Copilot
AI
Aug 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function documentation says it 'Lists the contents of a directory' but the implementation only returns files, not directories. Either update the documentation or include directories in the result.
| .map((file) => file.path) | |
| .map((entity) => entity.path) |
|
|
||
| /// Default structs defined within the language. | ||
| static final defaults = [error]; | ||
| static final defaults = [error, httpResponse, json, duration, dateTime]; |
Copilot
AI
Aug 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'mapEntry' struct is defined but not included in the defaults list, which means it won't be available for type resolution during compilation and runtime.
Uh oh!
There was an error while loading. Please reload this page.