fortran-src icon indicating copy to clipboard operation
fortran-src copied to clipboard

fortran-src builtin type checker doesn't report declaration type errors

Open dorchard opened this issue 4 years ago • 4 comments
trafficstars

Consider:

 program ty
   implicit none

   character :: x
   x = 42

 end program ty

The -t pass doesn't report anything fishy but I think it should (if would complain if I did x = 42 + "Hello" though. Why it this? Is this a case of a mismatch between user expectations and what is going on internally?

dorchard avatar Apr 12 '21 13:04 dorchard

I can't find evidence of Analysis.Types checking expression types for validity after gathering those types. -t,--typecheck calls Analysis.Types.analyseTypesWithEnv', which gathers variable types and annotates expressions in the AST.

The type error on x = 42 + "Hello" occurs when the expression doesn't have an IDType associated. It's not a "binop/assign type mismatch". For some reason, using a variable instead of a constant:

program ty
  implicit none

  integer :: x, y
  character(*) :: str
  str = x // y

end program ty

checks with no errors.

My understanding is that we don't do typechecking per se. We could add another pass that uses the generated TypeEnv and intrinsic function defs to typecheck expressions like in your example. We talked about yesterday this but I forgot -- did you do anything like that in CamFort?

Edit: Wonder if a typecheck pass would fit better in CamFort so we can treat it as another analysis.

raehik avatar Apr 13 '21 17:04 raehik

Sounds like we may just need to rename this analysis in fortran-src then so it's not misleading. Adding a proper type checking pass could fit will with CamFor yes.

dorchard avatar Apr 13 '21 19:04 dorchard

See analyseAndCheckTypesWithEnv

mrd avatar Apr 14 '21 09:04 mrd

I was wrong -- we do check for issues such as calling non-functions and bad array indexing. It doesn't extend to full consistency/mismatch checking.

analyseAndCheckTypesWithEnv is what --typecheck uses. It calls analyseTypesWithEnv' and returns any TypeErrors together with the other returns. The issue is that we're catching only a subset of (simple) type errors.

raehik avatar Apr 14 '21 10:04 raehik