Search code examples
haxehaxelib

Missing Return and Float should be Int


I have the codeblock like this and I am trying to get rid of the Float should be Int and Missing Return errors.

   package com.bykd.dev;

        @:final class Version
        {

            public static inline var SPLIT_CHAR : String = ".";

            public static var revisionKeyword : String = "Revision"; 

            private var _tag : String;

            private var _numbers : Array<Dynamic>;

 public static function create(pfx : String, rev : String = null, sfx : String = null) : Version
    {
        var nums : Array<Dynamic> = null; 
        nums = pfx.split(SPLIT_CHAR);
        if (rev != null)
        {
            nums.push(trimRevision(rev));
        }
        return new Version(nums, sfx);
             private static function trimRevision(rev : String) : String
            {
                var beg : Float = Math.NaN;
                var end : Float = Math.NaN; 
                beg = Std.string("$" + revisionKeyword + ": ").length; 
                end = rev.lastIndexOf(" $");
                return rev.substring(beg, end);   
            } 
        }

Errors are in the last lines :

  end = rev.lastIndexOf(" $");
                return rev.substring(beg, end);  

Any help would be highly appreciated.


Solution

  • Why use Float?

    var beg : Int = 0;
    var end : Int = 0;
    

    Also avoid Dynamic when possible

    var nums : Array<String> = null; 
    nums = pfx.split(SPLIT_CHAR);