summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semexprs.nim10
1 files changed, 4 insertions, 6 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 9f0696252..d76bd791e 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -191,10 +191,6 @@ proc semConv(c: PContext, n: PNode): PNode =
     case status
     of convOK:
       # handle SomeProcType(SomeGenericProc)
-      # XXX: This needs fixing. checkConvertible uses typeRel internally, but
-      # doesn't bother to perform the work done in paramTypeMatchAux/fitNode
-      # so we are redoing the typeRel work here. Why does semConv exist as a
-      # separate proc from fitNode?
       if op.kind == nkSym and op.sym.isGenericRoutine:
         result.sons[1] = fitNode(c, result.typ, result.sons[1])
       elif op.kind == nkPar and targetType.kind == tyTuple:
@@ -202,8 +198,10 @@ proc semConv(c: PContext, n: PNode): PNode =
     of convNotNeedeed:
       message(n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
     of convNotLegal:
-      localError(n.info, errGenerated, msgKindToString(errIllegalConvFromXtoY)%
-        [op.typ.typeToString, result.typ.typeToString])
+      result = fitNode(c, result.typ, result.sons[1])
+      if result == nil:
+        localError(n.info, errGenerated, msgKindToString(errIllegalConvFromXtoY)%
+          [op.typ.typeToString, result.typ.typeToString])
   else:
     for i in countup(0, sonsLen(op) - 1):
       let it = op.sons[i]
e the previous revision' href='/ahoang/Nim/blame/compiler/nimfix.nim?h=devel&id=4c870fc29374b89b1b61f0437c69166b7c400dfe'>^
da0fab704 ^
bf557a7cd ^
611d5d776 ^
2d9a24f3f ^
611d5d776 ^
caf2f6ecf ^

bf557a7cd ^




bf557a7cd ^

bf557a7cd ^
92c2a51bf ^
7f7b13a45 ^

92c2a51bf ^
7f7b13a45 ^
f484d1b20 ^
bf557a7cd ^




da0fab704 ^
2d9a24f3f ^
bf557a7cd ^

2d9a24f3f ^

bf557a7cd ^










caf2f6ecf ^
bf557a7cd ^
7333237be ^
611d5d776 ^

7333237be ^
da0fab704 ^
7d24656b0 ^
bf557a7cd ^


7f7b13a45 ^

bf557a7cd ^


2a0f7b5de ^
bf557a7cd ^


















ae53d1ecc ^


bf557a7cd ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


                            
                                         







                                                                            


                                                 
                     
                       



                               
                                  



                                                                    
                                                                  
                                                                
                                                                          
                                                                        
                                                                

                                                                      




                                                           

                          
                  
                                 

                                                     
                                       
 
                                                   




                                                       
                      
             

                    

                                     










                                                          
                      
                            
                                               

                                                
                                                          
                                              
                                                                                


                              

                                                     


                       
                           


















                                                                           


                                                              


                      
#
#
#           The Nim Compiler
#        (c) Copyright 2015 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## Nimfix is a tool that helps to convert old-style Nimrod code to Nim code.

import strutils, os, parseopt
import compiler/[options, commands, modules, sem,
  passes, passaux, nimfix/pretty,
  msgs, nimconf,
  extccomp, condsyms,
  modulegraphs, idents]

const Usage = """
Nimfix - Tool to patch Nim code
Usage:
  nimfix [options] projectfile.nim

Options:
  --overwriteFiles:on|off          overwrite the original nim files.
                                   DEFAULT is ON!
  --wholeProject                   overwrite every processed file.
  --checkExtern:on|off             style check also extern names
  --styleCheck:on|off|auto         performs style checking for identifiers
                                   and suggests an alternative spelling;
                                   'auto' corrects the spelling.
  --bestEffort                     try to fix the code even when there
                                   are errors.

In addition, all command line options of Nim are supported.
"""

proc mainCommand =
  registerPass verbosePass
  registerPass semPass
  gCmd = cmdPretty
  searchPaths.add options.libpath
  if gProjectFull.len != 0:
    # current path is always looked first for modules
    searchPaths.insert(gProjectPath, 0)

  compileProject(newModuleGraph(), newIdentCache())
  pretty.overwriteFiles()

proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
  var p = parseopt.initOptParser(cmd)
  var argsCount = 0
  gOnlyMainfile = true
  while true:
    parseopt.next(p)
    case p.kind
    of cmdEnd: break
    of cmdLongoption, cmdShortOption:
      case p.key.normalize
      of "overwritefiles":
        case p.val.normalize
        of "on": gOverWrite = true
        of "off": gOverWrite = false
        else: localError(gCmdLineInfo, errOnOrOffExpected)
      of "checkextern":
        case p.val.normalize
        of "on": gCheckExtern = true
        of "off": gCheckExtern = false
        else: localError(gCmdLineInfo, errOnOrOffExpected)
      of "stylecheck":
        case p.val.normalize
        of "off": gStyleCheck = StyleCheck.None
        of "on": gStyleCheck = StyleCheck.Warn
        of "auto": gStyleCheck = StyleCheck.Auto
        else: localError(gCmdLineInfo, errOnOrOffExpected)
      of "wholeproject": gOnlyMainfile = false
      of "besteffort": msgs.gErrorMax = high(int) # don't stop after first error
      else:
        processSwitch(pass, p)
    of cmdArgument:
      options.gProjectName = unixToNativePath(p.key)
      # if processArgument(pass, p, argsCount): break

proc handleCmdLine() =
  if paramCount() == 0:
    stdout.writeLine(Usage)
  else:
    processCmdLine(passCmd1, "")
    if gProjectName != "":
      try:
        gProjectFull = canonicalizePath(gProjectName)
      except OSError:
        gProjectFull = gProjectName
      var p = splitFile(gProjectFull)
      gProjectPath = p.dir
      gProjectName = p.name
    else:
      gProjectPath = getCurrentDir()
    loadConfigs(DefaultConfig) # load all config files
    # now process command line arguments again, because some options in the
    # command line can overwite the config file's settings
    extccomp.initVars()
    processCmdLine(passCmd2, "")
    mainCommand()

when compileOption("gc", "v2") or compileOption("gc", "refc"):
  GC_disableMarkAndSweep()

condsyms.initDefines()
defineSymbol "nimfix"
handleCmdline()