www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 977] New: Wrong line number reported for a missing comma in an array initializer within a struct initializer

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977

           Summary: Wrong line number reported for a missing comma in an
                    array initializer within a struct initializer
           Product: D
           Version: 1.006
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: deewiant gmail.com


struct S {
        int[] x;
}

S s =
{
        [
                1, 2, 3,

                4, 5, 6

                7, 8, 9 // error line number should be here (line 12)

        ]
}                       // but is here (line 15)
;

If an array is initialized directly and there's no struct initializer, the line
number is reported correctly.


-- 
Feb 17 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cbkbbejeap mailinator.com

Bug 977 depends on bug 3994, which changed state.

Bug 3994 Summary: Wrong line numbers inside AA/Array initializers
http://d.puremagic.com/issues/show_bug.cgi?id=3994

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


*** Issue 3994 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
            Version|1.006                       |D1 & D2
            Summary|Wrong line number reported  |Expressions inside a struct
                   |for a missing comma in an   |or array initializer get
                   |array initializer within a  |wrong line number
                   |struct initializer          |
         OS/Version|Windows                     |All
           Severity|minor                       |major



This happens because the parser scans across the whole initializer to determine
if it's an expression or an initializer.  Because it's already lexed the whole
initializer, the lexer's loc points to the end, and this is what is assigned to
each expression.  Not sure how to solve this without re-lexing the initializer.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com




 This happens because the parser scans across the whole initializer to determine
 if it's an expression or an initializer.  Because it's already lexed the whole
 initializer, the lexer's loc points to the end, and this is what is assigned to
 each expression.  Not sure how to solve this without re-lexing the initializer.
But it manages to give line numbers for errors that occur in the semantic analysis phase. The D compiler first lexes/parses the entire source file, then semantically analyses it. So it should be able to get this right. Two ways I can see to do it: - Remember the line number of every token just in case - Realise on hitting the 7 that it is no longer parseable as either an expression or an initialiser, and deliver the error there and then. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977






 This happens because the parser scans across the whole initializer to determine
 if it's an expression or an initializer.  Because it's already lexed the whole
 initializer, the lexer's loc points to the end, and this is what is assigned to
 each expression.  Not sure how to solve this without re-lexing the initializer.
But it manages to give line numbers for errors that occur in the semantic analysis phase. The D compiler first lexes/parses the entire source file, then semantically analyses it. So it should be able to get this right.
It lexes while it parses, so when the parser creates the ast it can use the current location of the lexer instead of storing in the tokens. This is very efficient and works everywhere except when arbitrary lookahead is required.
 Two ways I can see to do it:
 - Remember the line number of every token just in case
As a last resort. This would likely be a performance hit, and complicate the parser code in most places for no benefit.
 - Realise on hitting the 7 that it is no longer parseable as either an
 expression or an initialiser, and deliver the error there and then.
It would have to be parsing to find this error, while it scans it's only lexing. The relevant code is at 3185 and 3272 in parse.c The solution is probably to initially parse it one way and convert if wrong, preserving location information, but this might not be possible. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977


ponce <aliloko gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aliloko gmail.com



My patch proposal:

https://github.com/p0nce/dmd/commit/bedcd6e7dc43087afdf816cf00debba03aafd400

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/dc8b6ea10b4e76cddc0e13119443e286cff6ba6c


Bug 977

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 07 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977




Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6f9e42c84fc1d4fdd91d2387fe5bbdf549e8b018
fix Issue 977 - Expressions inside a struct or array initializer get wrong line
number

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 07 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=977


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 07 2012