CAST function parameter fragment is incorrectly calculated during parsing

Open
#224 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
sql
Domain
compilers

Research direction

Start by reproducing the issue with TSql180Parser and TSql170Parser using SELECT CAST('TEST' AS VARCHAR(20)), then inspect how the CAST parameter fragment is calculated. Done means the parameter fragment includes both 'TEST' and AS VARCHAR(20), while parsing still succeeds without errors.

Written by the indexing model from the issue text.

Description

Version - 180.78.1
Parser - TSql180Parser and TSql170Parser

Issue Description : When the fragment for the parameter in CAST function is calculated it consist only the "'Test'" part and does not contain the "AS VARCHAR(20)" section.

Steps to reproduce -

Try parsing the below SQL script with the parser:

SELECT CAST('TEST' AS VARCHAR(20))

Example -

using Microsoft.SqlServer.TransactSql.ScriptDom;

internal class Program
{
    static void Main(string[] args)
    {
        var script = "Example Script";
        var parser = new TSql180Parser(true);
        var fragment = parser.Parse(new StringReader(script), out var parseErrors);

        if (parseErrors.Count > 0)
        {
            foreach(var parseError in parseErrors)
                Console.WriteLine(parseError.Message);
        }
        else
        {
            Console.WriteLine("Parsed successfully");
        }
    }
}

Actual Output - Parameter fragment given by the parser - 'TEST'
Expected Output - Parameter fragment - 'TEST' AS VARCHAR(20)

Dominant language
GAP
Stars
277
Forks
43
Avg merge
6d 17h
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/SqlScriptDOM

All issues in microsoft/SqlScriptDOM

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.