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

Create _WinDate structure that stored Date values in a VO struct just like VO does. #773

Closed
RobertvanderHulst opened this issue Sep 6, 2021 · 19 comments

Comments

@RobertvanderHulst
Copy link
Member

See #735

@leon-ts
Copy link

leon-ts commented Sep 6, 2021

Wow, great!

RobertvanderHulst added a commit to X-Sharp/XSharpDev that referenced this issue Sep 24, 2021
* [Compiler tests] Added tests for X-Sharp/XSharpPublic#770 and X-Sharp/XSharpPublic#771

* [Compiler] Fixes #X-Sharp/XSharpPublic/issues/771
Create Usuals with IsByRef flag set to TRUE for OUT variables.
Also modified the RefKind for the Temporary local because the SynthesizedLocal type does not like RefKind.Out.

* [Tests] Added new group and moved C799 to fixed tests

* [Compiler] Added support + test for the new __WinDate type that represents a Date inside a VOSTRUCT or UNION.
Fixes #X-Sharp/XSharpPublic/issues/773

* Fixes #X-Sharp/XSharpPublic/issues/603  and adds test case R800

* Fixes #X-Sharp/XSharpPublic/issues/772

* Added test for #X-Sharp/XSharpPublic/issues/772

* Updated test R742 for the FoxPro array access with parenthesized indices

* [Compiler] Renamed Compiler option fox2 to FoxArraySupport.  Fixes #X-Sharp/XSharpPublic/issues/746 and R742

* Updated several keywords

* Updated Doc files

* [Compiler] More changes for FoxPro Array support. Also added test to runtime tests

* [Compiler tests] Added C802 - Internal Compiler Error with multiple PRIVATE &varName commands for X-Sharp/XSharpPublic#780

* [Compiler] Fixes #X-Sharp/XSharpPublic/issues/780
Fixes C802. marks test as fixed.

* [Compiler] temporary update FoxPro SQL

* [Compiler] Defaults for USUAL are noe default(usual) for non Fox dialects, and __Usual._NIL for the FoxPro dialect

* [Compiler] Updated version number. VSParser does not run the Preprocessor when ParserLevel = ParseLevel.Lex

* [Compiler] Only FoxPro dialect now uses __Usual._NIL for empty usuals. We now allow __Usual.NIL to be a field (Vulcan) or a property.
Also added test R803 to make sure that NIL is never overwritten

* [Tests] Added assertions to R803

* [Compiler] Fix problem with missing arguments passed to a function that expects a REF USUAL or OUT USUAL.
A Previous solution could lead to the __Usual._NIL value to become corrupted.

* [tests] Removed WAIT from 2 tests and marked tests as fixed.

* [Compiler] Change error message when they are passing NIL to a method / function that has a REF or OUT parameter

* [tests] Updated Runtime to 2.9

Co-authored-by: cpyrgas <chris@xsharp.eu>
@cpyrgas
Copy link

cpyrgas commented Oct 7, 2021

This has caused some problems unfortunately. This is from Leonid's code, which was compiling and running without errors previously:

prg(9,2): error XS0034: Operator '-' is ambiguous on operands of type 'DATE' and 'XSharp.__WinDate'
prg(10,2): error XS0030: Cannot convert type 'XSharp.__WinDate' to 'dword'

FUNCTION Start() AS VOID STRICT
	LOCAL nDays AS DWORD
	LOCAL dNow AS DATE
	LOCAL ts IS TEST_STRUCT
	
	dNow := Today()
	ts.dDate := Today()
	nDays := dNow - ts.dDate
	nDays := DWORD(_CAST, ts.dDate)

VOSTRUCT TEST_STRUCT
	MEMBER dDate AS DATE

@RobertvanderHulst
Copy link
Member Author

I think this are 2 different issues:

  1. I have added numeric operators to __WInDate. (+, - ). Apparently that was not needed and is confusing the compiler.
  2. I will add an explicit conversion from __WinDate to DWORD.

cpyrgas pushed a commit to X-Sharp/XSharpDev that referenced this issue Oct 7, 2021
@RobertvanderHulst
Copy link
Member Author

I reviewed case #1. This error does not happen because there are numeric operators on the __WinDate type, but because there are several numeric operators on the Date Type. We have these operators:

STATIC OPERATOR -(lhs AS DATE, rhs AS DATE) AS LONG
STATIC OPERATOR -(lhs AS DATE, days AS USUAL) AS USUAL
STATIC OPERATOR -(lhs AS DATE, days AS REAL8) AS DATE
STATIC OPERATOR -(lhs AS DATE, days AS LONG) AS DATE
STATIC OPERATOR -(lhs AS DATE, days AS INT64) AS DATE
STATIC OPERATOR -(lhs AS DATE, ts AS System.TimeSpan) AS DATE
STATIC OPERATOR -(lhs AS DATE, days AS DWORD) AS DATE
STATIC OPERATOR -(lhs AS DATE, days AS UINT64) AS DATE

The compiler does not know which one to choose.
I will change the compiler to detect a binary operation that involves a Date and a __WinDate and then to automatically cast the __WinDate side to Date.

BTW the operation nDays := dNow - ts.dDate returns a LONG (dDate can be larger than dNow). So nDays should be declared as LONG and not as DWORD. If you enable /vo4 this is not needed but if you then change
ts.dDate := Today()
to
ts.dDate := Today()+1
then nDays will have a value of UInt32.MaxValue

RobertvanderHulst added a commit to X-Sharp/XSharpDev that referenced this issue Oct 7, 2021
@leon-ts
Copy link

leon-ts commented Oct 7, 2021

Robert,

BTW the operation nDays := dNow - ts.dDate returns a LONG (dDate can be larger than dNow). So nDays should be declared as LONG and not as DWORD.

I just did this for an example so that for both cases I declare one variable. In a real application, the following code (template):
IF ( (dDate - st.dDate) > nSomeDays )

@leon-ts
Copy link

leon-ts commented Oct 8, 2021

Robert,
There are new errors:

LOCAL nDays AS DWORD
LOCAL ts IS TEST_STRUCT
	
nDays := 10
ts.dDate := Today()
ts.dDate += ( nDays - 1 ) // Error XS0034 Operator '+=' IS ambiguous ON operands OF type 'XSharp.__WinDate' and 'dword'
ts.dDate -= ( nDays - 1 ) // Error XS0034 Operator '-=' IS ambiguous ON operands OF type 'XSharp.__WinDate' and 'dword'
ts.dDate += 1 // Error XS0029 Cannot implicitly convert type 'int' TO 'XSharp.__WinDate'
ts.dDate -= 1 // Error XS0029 Cannot implicitly convert type 'int' TO 'XSharp.__WinDate'
ts.dDate++ // Error XS0035 Operator '++' is ambiguous on an operand of type 'XSharp.__WinDate'
ts.dDate-- // Error XS0035 Operator '--' is ambiguous on an operand of type 'XSharp.__WinDate'
	
LOCAL dStart, dEnd AS DATE
dStart := Today()
dEnd := dStart
	
FOR ts.dDate := dStart UPTO dEnd // Error XS0029 Cannot implicitly convert type 'int' TO 'XSharp.__WinDate'
NEXT

VOSTRUCT TEST_STRUCT
	MEMBER dDate AS DATE

@RobertvanderHulst
Copy link
Member Author

Leonid,
I will check to see why the compound (+= etc) assignments are failing. If you write this as regular assignments then these will work.
The for loop is a different thing. I'll see what we can do there. But do not expect these 2 changes to become part of the official 2.9 build. I do not want to delay this build for too much longer. People are getting impatient.

@cpyrgas
Copy link

cpyrgas commented Oct 11, 2021

Robert, maybe it's better to roll back completely the change with introducing _WinDate for now? I am afraid there will be problems in other people's code as well because of that. What would be the consequences of reverting the change (for now)? I think it's only that DATEs in structures will not be binary equal to VO, which is not really a big problem, is that right?

@RobertvanderHulst
Copy link
Member Author

Chris,
I do not think there will be consequences for others peoples code. This really only has effect on people that were using a DATE variable in a VOSTRUCT or UNION. So far Leonid / Comintec is the only customer that has reported to use this.

@cpyrgas
Copy link

cpyrgas commented Oct 11, 2021

I am sure there are more. The code in the asbau project used that as well.

@leon-ts
Copy link

leon-ts commented Oct 11, 2021

Guys,

In my projects, I have not found any other problems with the __WinDate type, besides the ones I described above. If suddenly this information will be useful to you for making a decision. For my part, I can only hope that these fixes, if they are not complex, will still get to version 2.9 or at least to the next patch after it. Since I have a lot of similar code.

@leon-ts
Copy link

leon-ts commented Oct 19, 2021

Robert,
In my project, I found another serious problem with the DATE type inside a VOSTRUCT. Assignment from a USUAL variable does not work. For example, reading from a DBF file:
somestrcut.dDate: = FieldGetSym(#DATEFIELD)

Here's a simple reproducible example:

LOCAL u AS USUAL
LOCAL ts IS TEST_STRUCT
u := Today()
ts.dDate := u
? ts.dDate // NULL_DATE instead of current date

VOSTRUCT TEST_STRUCT
	MEMBER dDate AS DATE

Also, please note that the debugger is showing the wrong field type (see screenshot):
Screenshot1

@RobertvanderHulst
Copy link
Member Author

Leonid,
For now add a (DATE) cast in front of the Right Hand Side of the expression.
ts.dDate := (DATE) u
This will be fixed asap.

The LOGIC text in the debugger is a copy/paste error and very easy to fix.

@RobertvanderHulst
Copy link
Member Author

Leonid,
Can you confirm that this works, with the exception of the assignment of the usual to the __WinDate element ?

@cpyrgas
Copy link

cpyrgas commented Oct 21, 2021

Robert, all the issues mentioned here #773 (comment) still exist

@cpyrgas
Copy link

cpyrgas commented Oct 21, 2021

Arghh, thought the test (C804) had included those, but it doesn't. Updating it now.

cpyrgas pushed a commit to X-Sharp/XSharpDev that referenced this issue Oct 21, 2021
@leon-ts
Copy link

leon-ts commented Oct 21, 2021

Robert,
I have nothing to add to what Chris said. The errors I mentioned in the section "There are new errors" remained in the new 2.9 compiler.

cpyrgas pushed a commit to X-Sharp/XSharpDev that referenced this issue Oct 25, 2021
RobertvanderHulst added a commit that referenced this issue Oct 25, 2021
…warded to the __Date type.

Also fixed a problem in __Date:Subtract(USUAL)
@cpyrgas
Copy link

cpyrgas commented Oct 30, 2021

Confirm fixed

@cpyrgas cpyrgas closed this as completed Oct 30, 2021
@leon-ts
Copy link

leon-ts commented Nov 5, 2021

Robert,
It works well now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants