Comments (2)
There are two issues here. One is in the desugaring of struct-update expressions int struct-creation expressions. And the other is in the error message for struct-creation using an unqualified name, when the package is imported qualified. For example, if you wrote this:
makeNegative x = FloatingPoint.Half { sign = True }
Then you get the same error:
Error: "MakeNegative.bs", line 6, column 38: (T0140)
Cannot access fields in this expression since its type
`FloatingPoint.FloatingPoint' has not been imported. Perhaps an import
statement is missing, e.g., `import FloatingPoint::*;'
The desugaring is producing a struct-creation function with unqualified field names. That is, this:
x { sign = True }
becomes this:
FloatingPoint { sign = True; exp = x.exp; sfd = x.sfd }
This occurs during typecheck and is due to the definition of tiExpr
(in TCheck.hs
) for CStructUpd
.
The code for this has the field IDs that the user wrote (with the positions that the user wrote them) and it has the field IDs that it looked up for the type (with the position of where they are defined, in this case in the library). When creating the new expression, the looked up IDs are used, which is why the position is bad.
The looked-up IDs are qualified, and the user generally writes unqualified names, so the code does need to account for this when it is comparing IDs between the two. The way it does this, though, is just to unqualify the looked-up IDs -- but it doesn't unqualify the user's IDs. This creates a further bug where the desugaring fails to include the user's updated value (because the name didn't match). And, in fact, because the fields are unqualified, the code can fail to notice when the user gave a bogus qualifier (on fields after the first one). This code is accepted (when not importing qualified):
makeNegative x = x { sign = True; Foo.exp = 0 }
I'll will look at fixing all of this in the desugaring. The error message when you write a struct-creation using unqualified names is still misleading, but that is a separate issue, and I haven't looked into why that's happening. But I can see about getting to that after the desugaring.
from bsc.
The reason why failing to qualify the field name (in either a struct update or struct creation expression) results in an error message that the type wasn't imported is explained by the comment at lines 570-572 in TIMonad.hs
. That comment is in a function that returns a tuple of information about a type, including whether the type is visible to the user. Unfortunately, the way that it computes whether the type is visible is to see if the unqualified name is in the symbol table. This doesn't work for packages that were imported qualified.
The comment suggests an alternative way to determine visibility: take the qualifier from the type and see if it appears in the import list (which would need to be added to the typechecker's state). That seems to hackish. I suspect that the appropriate thing to do is to add a field to the symbol table that says whether the name is visible; when building the symbol table, it would get set appropriately. This would better handle selective importing etc. It might mean, though, that when re-adding a package to the symbol table (because it was imported by an import), we couldn't just overwrite the existing field, we'd have to merge the entries, to preserve that bit of info.
I have a PR that fixes the desugaring, but I don't think I'll tackle the error message. I'll probably open another issue for that, and close this one.
from bsc.
Related Issues (20)
- bluesim simulation result is different from verilog simulation, does bluesim have bug implementing UInt#(n) when n is big (eg., 72)? HOT 1
- Bluesim leaves junk in loaded registers if the full range of hex digits isn't specified HOT 3
- uppercase names not allowed in interface property `arg_names` HOT 4
- bsc ignores `always_ready` when checking for duplicate wires
- module verilog does not allow sharing ports among conflicting methods
- Improve the mechanism for testing Bluespec Inc bug 1490 HOT 3
- `-dparsed` output produces invalid register updates with BSV HOT 2
- `-dparsed` produces invalid BSV module function that takes another module as an argument HOT 2
- Missing `Ord Bool` instance HOT 7
- Static check of file descriptor argument to tasks like $fgetc HOT 3
- Testsuite reports an error getting BSC version HOT 2
- Internal Compiler Error when quoting a character value. HOT 4
- Bluesim's symbol-probing interface has wrong values for FIFO
- Unresolved numeric contexts that should be resolvable HOT 6
- Verilog import fails in macro substitution HOT 2
- Unexpected syntax error HOT 1
- expandPorts.tcl has hardcoded paths which do not exist. HOT 1
- Unexpected behavior in Stmt sequence when using par HOT 2
- Bluesim divide-by-zero behavior is inconsistent on arm64 HOT 2
- Type synonyms with phantom parameters can lead to strange behaviors (E.g., compiler hang) HOT 4
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 bsc.